gathos Posted April 6, 2009 Share Posted April 6, 2009 hey guys, I'm looking for the error in my code. I can't seem to find it. anyways the situation is, i have a gallery database, i have my form setup to give each image a name and description. hit submit and then the it supposed to update the database with the description. heres my code for my form page editrec.php: <form id="form1" name="form1" method="post" action="processeditrec.php"> <?php $id = $_GET["id"]; $name = $_GET["name"]; $page = $_GET['page']; mysql_connect("localhost", "username*****", "password****") or die(mysql_error()); mysql_select_db("database*****") or die(mysql_error()); $result = mysql_query("SELECT * FROM samples WHERE id='$id'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $oldname = $row['name']; $oldfilename = $row['filename']; $oldsdesc = $row['sdesc']; $oldldesc = $row['ldesc']; ?> <input name="passid" type="hidden" id="passid" value="<? echo $id; ?>" /> <? function strip_ext($name) { $ext = strrchr($name, '.'); if($ext !== false) { $name = substr($name, 0, -strlen($ext)); } return $name; }; $remove_exts = strip_ext($oldfilename); ?> <input name="page" type="hidden" id="page" value="<? echo $page ?>" /> <br /> <table width="100%" border="0"> <tr> <td width="20%" rowspan="2"><img src="images/<? echo $oldfilename; ?>" alt="" height="100" /></td> <td width="26%">name: <input name="name" type="text" id="name" value="<? echo $remove_exts ?>" class="textfield" /></td> <td>Short Description: <input type="text" name="sdesc" id="sdesc" value="<? echo $oldsdesc; ?>"/></td> </tr> <tr> <td colspan="2" align="left" valign="top"><p>Description:<br /> <textarea name="ldesc" id="ldesc" cols="45" rows="5"><? echo $oldldesc; ?></textarea> <br /> </p></td> </tr> </table> <br /> <table width="100%" border="0"> <tr> <td> </td> <td> </td> </tr> </table> <br /> <table width="100%" border="0"> <tr> <td width="25%" align="left" valign="top"> </td> <td width="25%" align="left" valign="top"> </td> <td width="25%" align="left" valign="top"> </td> <td width="25%" align="left" valign="top"> </td> </tr> </table> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> </p> </form> heres my code for my processing page processeditrec.php: <? $name = $_POST['name']; $sdesc = $_POST['sdesc']; $ldesc = $_POST['ldesc']; $id = $_POST['passid']; $obscurity = $_POST['obscurity']; $page = $_POST['page']; mysql_connect("localhost", "username*****", "password*****") or die(mysql_error()); mysql_select_db("database*****") or die(mysql_error()); $sql = " UPDATE sample SET name= '$name', sdesc= '$sdesc', ldesc= '$ldesc', obscurity= '$obscurity' WHERE id = '$id'"; $result = mysql_query($sql); if ($result){ echo "Your record was updated!<br/>"; } else { echo "An error occured during update!<br/>"; } ?> <html> <head> </head> <br> <a href="displayrec.php">Click here to go to the gallery.</a> </html> i can't figure out what is going on. it's probably something simple but, well i can't find it. It won't update the databse with the new info, and on the process page i get " an error occured during the update" but i have no idea how to get it to give me more information. thanks for your help, gathos. Link to comment https://forums.phpfreaks.com/topic/152848-solved-i-need-a-second-pair-of-eyes-to-check-out-my-code-for-an-error/ Share on other sites More sharing options...
Maq Posted April 6, 2009 Share Posted April 6, 2009 ey guys, I'm looking for the error in my code. I can't seem to find it. What makes you think there's an error? What happens, or doesn't happen? EDIT: A little debugging... You shouldn't use short hand php tags, use <?php. Change this line to: $result = mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/152848-solved-i-need-a-second-pair-of-eyes-to-check-out-my-code-for-an-error/#findComment-802674 Share on other sites More sharing options...
Brian W Posted April 6, 2009 Share Posted April 6, 2009 Are you getting an error or what is wrong with it? Are you sure short-tags are enabled? Link to comment https://forums.phpfreaks.com/topic/152848-solved-i-need-a-second-pair-of-eyes-to-check-out-my-code-for-an-error/#findComment-802675 Share on other sites More sharing options...
gathos Posted April 6, 2009 Author Share Posted April 6, 2009 thanks for the qick reply, i efited the message to include my proble, lol. Link to comment https://forums.phpfreaks.com/topic/152848-solved-i-need-a-second-pair-of-eyes-to-check-out-my-code-for-an-error/#findComment-802677 Share on other sites More sharing options...
Maq Posted April 6, 2009 Share Posted April 6, 2009 thanks for the qick reply, i efited the message to include my proble, lol. Read my edit about the or die statement. That will give you a descriptive error message if your query is failing. Link to comment https://forums.phpfreaks.com/topic/152848-solved-i-need-a-second-pair-of-eyes-to-check-out-my-code-for-an-error/#findComment-802681 Share on other sites More sharing options...
gathos Posted April 6, 2009 Author Share Posted April 6, 2009 thanks fo the code help, apparently i forgot the ad an s my table name it was sample instead of samples. $result = mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/152848-solved-i-need-a-second-pair-of-eyes-to-check-out-my-code-for-an-error/#findComment-802684 Share on other sites More sharing options...
ambo Posted April 6, 2009 Share Posted April 6, 2009 Dont Know if this is it but i usually use also you should add a limit 1 to your query if your only going to be updating 1 row and after that you have to start the loop <?php $result = mysql_query("SELECT * FROM samples WHERE id='$id' LIMIT 1") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { //Rows are being looped even though you only //call one row with limit 1 $oldname = $row['name']; $oldfilename = $row['filename']; $oldsdesc = $row['sdesc']; $oldldesc = $row['ldesc']; }// end row loop ?> Link to comment https://forums.phpfreaks.com/topic/152848-solved-i-need-a-second-pair-of-eyes-to-check-out-my-code-for-an-error/#findComment-802690 Share on other sites More sharing options...
Maq Posted April 6, 2009 Share Posted April 6, 2009 If you're updating 1 record you don't need a loop. Id's are usually unique any way so there's no need for LIMIT 1. EDIT again: ^ Link to comment https://forums.phpfreaks.com/topic/152848-solved-i-need-a-second-pair-of-eyes-to-check-out-my-code-for-an-error/#findComment-802696 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.