Jump to content

lbaxterl

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Everything posted by lbaxterl

  1. Sorry i posted code i was messing around with there here is the working code (in firefox at least), it still outputs the last record having a comma after it. <?php include "config.inc.php"; $num = 1; function checkNum($num){ return ($num%2) ? TRUE : FALSE; } $result = mysql_query( "SELECT photo_id, photo_filename FROM gallery_photos WHERE photo_category= 6 AND promo= 1 "); $nr = mysql_num_rows( $result ); $NumOfRecords = mysql_num_rows($result); while($row = mysql_fetch_array($result)) { $id = $row['photo_id']; $img = $row['photo_filename']; if(checkNum($num) === TRUE){ echo " { src: 'admin/photos/".$img."', dir: 'left' },"; $num++; } else{ echo " { src: 'admin/photos/".$img."', dir: 'right' },"; $num++; } } ?>
  2. I have the following script which outputs different results based on weather a result is odd or even, pretty simple. The prblem lies with the very last result ouputted, as you can see from the code it will have a comma trailing it, which causes IE to not display the gallery. Can Anyone advise me on how to remove this last comma/echo the last result differently. Thank you <?php include "config.inc.php"; $num = 1; function checkNum($num){ return ($num%2) ? TRUE : FALSE; } $result = mysql_query( "SELECT photo_id, photo_filename FROM gallery_photos WHERE photo_category= 6 AND promo= 1 "); $nr = mysql_num_rows( $result ); $NumOfRecords = mysql_num_rows($result); while($row = mysql_fetch_array($result)) { $id = $row['photo_id']; $img = $row['photo_filename']; if(checkNum($num) === TRUE){ echo " { src: 'admin/photos/".$img."', dir: 'left' },"; $num++; } elseif ($num == $NumOfRecords) { echo " { src: 'admin/photos/".$img."', dir: 'left' }"; } else{ echo " { src: 'admin/photos/".$img."', dir: 'right' },"; $num++; } } ?>
  3. Ignore the last message, It isn't working as expected. I have the boxes checking based off the values in the database problem is if i check say the 10th row of the table and submit them it doesn't update that row of the database it updates the next blank one? I hope that makes sense. Thanks again
  4. Thanks, that was a big help, although that way didn't update the values in the db, I was able to modify it though, heres the code if your interested: <td align="center"><input name="published[]" type="checkbox" id="published" value="1" <? echo $rows['published'] == 1 ? ' checked="checked"' : ''; ?>></td> Thanks a lot! I appreciate it!
  5. I am having trouble setting a checkbox to "checked" if the row "published" is set to "1" (0 being not checked). I know this involves an if published==1 then print "checked", but i just cant get it to work. Any help would be greatly apprecatied: <?php include "base.php"; $sql="SELECT * FROM project"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center"><strong>title</strong></td> <td align="center"><strong>Published</strong></td> <td align="center"><strong>Promoted</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ $pub = $rows['publised']; ?> <tr> <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td> <td align="center"><? echo $rows['title']; ?></td> <td align="center"><input name="published[]" type="checkbox" id="published" value="<? echo $rows['published']; ?>"></td> <td align="center"><input name="promoted[]" type="text" id="promoted" value="<? echo $rows['promoted']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE project SET published='$published[$i]', promoted='$promoted[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update_multiple.php"); } mysql_close(); ?>
  6. thank you so much need to save as ansi files, is there a easy way to convert them all in dreamweaver?
  7. sorry there was no white space i double taped enter before posting the code stupidly sorry, any other ideas could it be a server issue?
  8. Im creating a login form but everytime i try to output a header or start a session i get errors: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /web/users/e5034824/Test/confirmlogin.php:1) in /web/users/e5034824/Test/confirmlogin.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /web/users/e5034824/Test/confirmlogin.php:1) in /web/users/e5034824/Test/confirmlogin.php on line 2 <?php session_start(); $username = $_POST['myusername']; $password = $_POST['mypassword']; require 'common.php'; $q = "SELECT id FROM members WHERE username = '$username' AND password = '$password'"; $result = $mysqli->query($q) or die(mysqli_error()); if (mysqli_num_rows($result) == 1) { $user = $result->fetch_array(MYSQLI_NUM); $_SESSION['admin'] = $user[0]; // Sets the session to the user's ID } else { $message = "User Name Not Recongised, Please Try Again!"; echo $message . ' <meta HTTP-EQUIV="refresh" content=5;url="login.php"/>'; } ?> I always get the header error message but have no clue on how to fix it any ideas?
  9. thanks ive implemented the code but now im being bombarded with errors: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /web/users/e5034824/Test/confirmlogin.php:1) in /web/users/e5034824/Test/confirmlogin.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /web/users/e5034824/Test/confirmlogin.php:1) in /web/users/e5034824/Test/confirmlogin.php on line 2 <?php session_start(); $username = $_POST['myusername']; $password = $_POST['mypassword']; require 'common.php'; $q = "SELECT id FROM members WHERE username = '$username' AND password = '$password'"; $result = $mysqli->query($q) or die(mysqli_error()); if (mysqli_num_rows($result) == 1) { $user = $result->fetch_array(MYSQLI_NUM); $_SESSION['admin'] = $user[0]; // Sets the session to the user's ID } else { $message = "User Name Not Recongised, Please Try Again!"; echo $message . ' <meta HTTP-EQUIV="refresh" content=5;url="login.php"/>'; } ?> I always get the header error message but have no clue on how to fix it any ideas?
  10. Hi im implementing a login form in my site and i wanted to know how i would adopt it to use sessions, allowing access to the admin page only if the user is logged in. Ive posted the login form and the confirm login script below any help appreciated. Login form: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <style type="text/css"> body { text-align: center; font-family: helvetica; } #loginForm { padding: 1em; background: #e3e3e3; width: 260px; margin: 3em auto 0; text-align: left; } </style> <body> <div id="loginForm"> <form name="form1" method="post" action="confirmlogin.php"> <h2>LOGIN</h2> <p>Username: <input type="text" name="myusername" id="myusername" /></p> <p>Password: <input type="text" name="mypassword" id="mypassword"/></p> <p><input type="submit" value="Login" name="submit" /></p> </form> </div> </body> </html> confirmlogin.php <?php $username = $_POST['myusername']; $password = $_POST['mypassword']; require 'common.php'; $q = "SELECT id FROM members WHERE username = '$username' AND password = '$password'"; $result = $mysqli->query($q) or die(mysqli_error()); if (mysqli_num_rows($result) == 1) { echo ' <meta HTTP-EQUIV="refresh" content=0;url="admin.php"/>'; } else { $message = "User Name Not Recongised, Please Try Again!"; echo $message . ' <meta HTTP-EQUIV="refresh" content=5;url="login.php"/>'; } ?> thank you
  11. ok the servers back up! now its outputting these errors but echoing the $source and $target: Warning: move_uploaded_file(img/photo/n656985202_6030227_7816996.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /web/users/e5034824/Test/admin.php on line 31 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpij8aCM' to 'img/photo/n656985202_6030227_7816996.jpg' in /web/users/e5034824/Test/admin.php on line 31
  12. i think were getting somewhere when insert the code you gave: print_r($_FILES['fupload']); i get this message: Array ( [name] => Capture.jpg [type] => [tmp_name] => [error] => 2 => 0 )
  13. the target returns img/photo/capture.jpg. the source returns nothing
  14. removed the add slashes, it didnt work, the info is still entered into the database though! thanks for the help guys
  15. think we may have found the problem i echos the $source and $target and it seems like the source is empty, the message reads "Success! Your file has been uploaded . . img/photo/Capture.jpg " heres the code <?php require 'functions.php'; require 'common.php'; if(isset($_FILES['fupload'])) { $imagedir = 'img/photo/'; $filename = addslashes($_FILES['fupload']['name']); $source = $_FILES['fupload']['tmp_name']; $target = $imagedir . $filename; $description = addslashes($_POST['description']); $category = addslashes($_POST['category']); $title = addslashes($_POST['title']); $path = $filename; $thumb = $filename; // Validates the form input if(strlen($_POST['description']) < 4) $error['description'] = '<p class="alert">Please enter a description for your photo. </p>'; if(strlen($_POST['title']) < 1) $error['title'] = '<p class="alert">Please enter a title for your photo. </p>'; if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename)) $error['no_file'] = '<p class="alert">Select a image to upload</p>'; if(!$error) { move_uploaded_file($source, $target); $q = "INSERT INTO photo (title, description, source, thumb, category) VALUES('$title', '$description', '$path', '$thumb', '$category')"; $result = $mysqli->query($q) or die(mysqli_error($mysqli)); if($result) { echo "Success! Your file has been uploaded . $source . $target"; } } // end preg_match } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="css/default.css" /> <title>My Photos</title> </head> <body> <h1>My Photos</h1> <ul><?php getPhotos(); ?></ul> <h1>Upload a Photo</h1> <form enctype="multipart/form-data" method="post" action="admin.php"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <p><input type="file" name="fupload" /></p> <p><label for="description">Enter a Description: </label> </p> <p> <textarea rows="6" cols="50" id="description" name="description"></textarea></p> Enter a title: <input type="text" name="title" size="25" id="title" /><br/> Please choose a category: <select name="category"> <option value="">Select...</option> <option value="sports">Sports</option> <option value="london">London</option> <option value="macro">Macro</option> <option value="landscapes">Landscapes</option> <option value="local">Local</option> </select> <p><input type="submit" value="Upload Photo" name="submit" /></p> </form> <?php if ($error['no_file']) echo $error['no_file']; if ($error['description']) echo $error['description']; if ($error['title']) echo $error['title']; ?> <br /> </body> </html>
  16. the file im testing on is "capture.jpg" im abit of a php n00b sorry should i remove the addslashes?
  17. sorry i didnt copy/paste it properly, there is no error, the file just doesn't appear in the img folder
  18. sorry i didnt copy/paste it properly, there is no error, the file just doesn't appear in the img folder
  19. Hi Ive wrote a upload script for a photo website im making and ive cam across a unusual problem. The script inserts all the values into the databse correctly and displays "file upload successfull" but the photos are not copying onto the server. any help will be appreciated, thank you! <?php require 'functions.php'; require 'common.php'; if(isset($_FILES['fupload'])) { $imagedir = 'img/photo/'; $filename = addslashes($_FILES['fupload']['name']); $source = $_FILES['fupload']['tmp_name']; $target = $imagedir . $filename; $description = addslashes($_POST['description']); $category = addslashes($_POST['category']); $title = addslashes($_POST['title']); $path = $filename; $thumb = $filename; // Validates the form input if(strlen($_POST['description']) < 4) $error['description'] = '<p class="alert">Please enter a description for your photo. </p>'; if(strlen($_POST['title']) < 1) $error['title'] = '<p class="alert">Please enter a title for your photo. </p>'; if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename)) $error['no_file'] = '<p class="alert">Select a image to upload</p>'; if(!$error) { move_uploaded_file($source, $target); $q = "INSERT INTO photo (title, description, source, thumb, category) VALUES('$title', '$description', '$path', '$thumb', '$category')"; $result = $mysqli->query($q) or die(mysqli_error($mysqli)); if($result) { echo "Success! Your file has been uploaded"; } } // end preg_match } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="css/default.css" /> <title>My Photos</title> </head> <body> <h1>My Photos</h1> <ul><?php getPhotos(); ?></ul> <h1>Upload a Photo</h1> <form enctype="multipart/form-data" method="post" action="admin.php"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <p><input type="file" name="fupload" /></p> <p><label for="description">Enter a Description: </label> </p> <p> <textarea rows="6" cols="50" id="description" name="description"></textarea></p> Enter a title: <input type="text" name="title" size="25" id="title" /><br/> Please choose a category: <select name="category"> <option value="">Select...</option> <option value="sports">Sports</option> <option value="london">London</option> <option value="macro">Macro</option> <option value="landscapes">Landscapes</option> <option value="local">Local</option> </select> <p><input type="submit" value="Upload Photo" name="submit" /></p> </form> <?php if ($error['no_file']) echo $error['no_file']; if ($error['description']) echo $error['description']; if ($error['title']) echo $error['title']; ?> <br /> </body> </html>
  20. Hi Ive just came across this syntax error and have no idea on how to go about fixing it hope someone can help? Im using Php myadmin # Server version: 5.0.45 # Protocol version: 10 Here is the error: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES('test my a', 'img/photo/tab_bg.gif', 'img/thumb/tab_bg.gif', '')' at line 1" <?php require 'config.php'; require 'functions.php'; require 'common.php'; if(isset($_FILES['fupload'])) { $filename = addslashes($_FILES['fupload']['name']); $source = $_FILES['fupload']['tmp_name']; $target = $path_to_image_directory . $filename; $description = $_POST['description']; $category = addslashes($_POST['category']); $source = $path_to_image_directory . $filename; $thumb = $path_to_thumbs_directory . $filename; // Validates the form input if(strlen($_POST['description']) < 4) $error['description'] = '<p class="alert">Please enter a description for your photo. </p>'; if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename)) $error['no_file'] = '<p class="alert">Please select an image, dummy! </p>'; if(!$error) { move_uploaded_file($source, $target); $q = "INSERT INTO photo (description, source, thumb, category,) VALUES('$description', '$source', '$thumb', '$category')"; $result = $mysqli->query($q) or die(mysqli_error($mysqli)); if($result) { echo "Success! Your file has been uploaded"; } createThumbnail($filename); } // end preg_match } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="css/default.css" /> <title>My Photos</title> </head> <body> <h1>My Photos</h1> <ul><?php getPhotos(); ?></ul> <h1>Upload a Photo</h1> <form enctype="multipart/form-data" method="post" action="admin.php"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <p><input type="file" name="fupload" /></p> <p><label for="description">Enter a Description: </label> <textarea rows="6" cols="50" id="description" name="description"></textarea></p> Please choose a category: <select name="select"> <option>Sports</option> <option>London</option> <option>Macro</option> <option>Landscapes</option> <option>Local</option> </select> <p><input type="submit" value="Upload Photo" name="submit" /></p> </form>
  21. Hi, im currently building a photography portfolio website for ym dissertation and i have a quick question. The site has several categories of photos, would it be easier storing all in photos in one table and adding a album and field or storing each separate category,of photos, into its own table? I have a script which gets the photos from the database which is below, if its easier storing all the photos in one table how would i go about modifying this script to select the photos with a specific category. I hope that makes sense. thanks <?php require "common.php"; $q = "SELECT id, title, source FROM sports"; $result = $mysqli->query($q) or die(mysql_error($mysqli)); if ($result) { while ($row = $result->fetch_object()) { $title = $row->title; $source = $row->source; $id = $row->id; echo "<a class='gallery' rel='usa' id='$id' alt='$title' href='img/sports/$source'> <img src='img/sports_tn/$source' /> </a> \n"; } } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.