sandbudd Posted April 7, 2009 Share Posted April 7, 2009 hey guys here is just a piece of the code because I think this is where the problem is... The database displays fine but when I click to update it does not update the database? <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE $tbl_name SET company='$company[$i]', address='$address[$i]', city='$city[$i]', state='$state[$i]', phone='$phone[$i]', asian='$asian[$i]', american='$american[$i]', coffee='$coffee[$i]', fun='$fun[$i]', italian='$italian[$i]', mexican='$mexican[$i]', seafood='$seafood[$i]', upscale='$upscale[$i]', recommend='$recommend[$i]', email='$email[$i]', website='$website[$i]', photo='$photo[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update.php"); } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/153015-php-update-to-database/ Share on other sites More sharing options...
Maq Posted April 7, 2009 Share Posted April 7, 2009 $result1=mysql_query($sql1) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/153015-php-update-to-database/#findComment-803659 Share on other sites More sharing options...
revraz Posted April 7, 2009 Share Posted April 7, 2009 Is there a ID 0? Where does $count get set? Quote Link to comment https://forums.phpfreaks.com/topic/153015-php-update-to-database/#findComment-803663 Share on other sites More sharing options...
sandbudd Posted April 7, 2009 Author Share Posted April 7, 2009 here is the complete file..its long thats why I didnt send it all first... <?php require_once('settings.php'); checkLogin('1 2'); ?> <style type="text/css"> <!-- .style1 { font-family: Arial, Helvetica, sans-serif; font-size: 18px; color: #0000FF; } --> </style> <br /><br /> <link href="css/styles.css" rel="stylesheet" type="text/css" /> <div id="container" style="text-align:center;width:230px;"> <?php echo 'Hello <em><b><u>' . get_username ( $_SESSION['user_id'] ) . '</u></b></em>!<br />You are now logged in.<br /><br /><a href="update_profile.php" title="update your profile">Click here</a> to update your profile.'; /* we show the manage users link only if the logged in member has admin rights */ if ( isadmin ( $_SESSION['user_id'] ) ): ?> <br /><br /> It seems that you're an admin. You may <a href="manage_users.php" title="manage users">manage users</a> or <a href="admin_settings.php" title="edit site settings">edit site settings</a>. <?php endif; ?> <br /><br /> <a href="logout.php">logout</a> </div><br /><br /> <table width="50%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="50%" align="center" valign="top"><a href="insert.php">Insert Customer</a></td> <td width="50%" align="center" valign="top"><a href="update.php">Update/Edit Customer</a></td> </tr> </table> <hr /> <?php $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY company ASC"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> </p> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td colspan="5" align="left" valign="top"><img src="../images/smalllogo.png" width="500" height="79" /><br /> <br /></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td width="25%" align="left" valign="top">Company</td> <td width="34%" align="left" valign="top"><input name="company[]" type="text" id="company" value="<? echo $rows['company']; ?>"></td> <td colspan="3" align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top">Address</td> <td align="left" valign="top"><input name="address[]" type="text" id="address" value="<? echo $rows['address']; ?>"></td> <td colspan="3" align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top">City</td> <td align="left" valign="top"><input name="city[]" type="text" id="city" value="<? echo $rows['city']; ?>"></td> <td colspan="3" align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top">State</td> <td align="left" valign="top"><input name="state[]" type="text" id="state2" value="<? echo $rows['state']; ?>"></td> <td colspan="3" align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top">Phone</td> <td align="left" valign="top"><input name="phone[]" type="text" id="state" value="<? echo $rows['phone']; ?>"></td> <td colspan="3" align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td colspan="3" align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top">Asian</td> <td align="left" valign="top"><input name="asian" type="text" id="asian" value="<? echo $rows['asian']; ?>" /></td> <td colspan="3" align="left" valign="top">1 = true leave blank if false</td> </tr> <tr> <td>American:</td> <td align="left" valign="top"><input name="american" type="text" id="american" value="<? echo $rows['american']; ?>" /></td> <td colspan="3" align="left" valign="top">1 = true leave blank if false</td> </tr> <tr> <td>Coffee:</td> <td align="left" valign="top"><input name="coffee" type="text" id="coffee" value="<? echo $rows['coffee']; ?>" /></td> <td colspan="3" align="left" valign="top">1 = true leave blank if false</td> </tr> <tr> <td>Fun Food:</td> <td align="left" valign="top"><input name="fun" type="text" id="fun" value="<? echo $rows['fun']; ?>" /></td> <td colspan="3" align="left" valign="top">1 = true leave blank if false</td> </tr> <tr> <td>Italian:</td> <td align="left" valign="top"><input name="italian" type="text" id="italian" value="<? echo $rows['italian']; ?>" /></td> <td colspan="3" align="left" valign="top">1 = true leave blank if false</td> </tr> <tr> <td>Mexican:</td> <td align="left" valign="top"><input name="mexican" type="text" id="mexican" value="<? echo $rows['mexican']; ?>" /></td> <td colspan="3" align="left" valign="top">1 = true leave blank if false</td> </tr> <tr> <td>Seafood</td> <td align="left" valign="top"><input name="seafood" type="text" id="seafood" value="<? echo $rows['seafood']; ?>" /></td> <td colspan="3" align="left" valign="top">1 = true leave blank if false</td> </tr> <tr> <td>Upscale</td> <td align="left" valign="top"><input name="upscale" type="text" id="upscale" value="<? echo $rows['upscale']; ?>" /></td> <td colspan="3" align="left" valign="top">1 = true leave blank if false</td> </tr> <tr> <td> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td>Recommend</td> <td align="left" valign="top"><input name="recommend" type="text" id="recommend" value="<? echo $rows['recommend']; ?>" /></td> <td colspan="3" align="left" valign="top">1 = true leave blank if false</td> </tr> <tr> <td>Email:</td> <td align="left" valign="top"><input name="email" type="text" id="email" value="<? echo $rows['email']; ?>" /></td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td>Website</td> <td align="left" valign="top"><input name="website" type="text" id="website" value="<? echo $rows['website']; ?>" /></td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top">Image</td> <td align="left" valign="top"><input name="photo" type="text" id="photo" value="<? echo $rows['photo']; ?>" /></td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td colspan="5" align="left" valign="top"><hr /></td> </tr> <?php } ?> <tr align="left" valign="top"> <td colspan="3"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <div align="center"> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE $tbl_name SET company='$company[$i]', address='$address[$i]', city='$city[$i]', state='$state[$i]', phone='$phone[$i]', asian='$asian[$i]', american='$american[$i]', coffee='$coffee[$i]', fun='$fun[$i]', italian='$italian[$i]', mexican='$mexican[$i]', seafood='$seafood[$i]', upscale='$upscale[$i]', recommend='$recommend[$i]', email='$email[$i]', website='$website[$i]', photo='$photo[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update.php"); } mysql_close(); ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/153015-php-update-to-database/#findComment-803673 Share on other sites More sharing options...
mrMarcus Posted April 7, 2009 Share Posted April 7, 2009 you suing register_globals? looks like it. instead of : if ($Submit) use : if (isset ($_POST['Submit'])) and update the rest of your page/site accordingly 'cause register_globals() is being taken out in PHP 6. Quote Link to comment https://forums.phpfreaks.com/topic/153015-php-update-to-database/#findComment-803677 Share on other sites More sharing options...
sandbudd Posted April 7, 2009 Author Share Posted April 7, 2009 still does not update? Quote Link to comment https://forums.phpfreaks.com/topic/153015-php-update-to-database/#findComment-803680 Share on other sites More sharing options...
sandbudd Posted April 7, 2009 Author Share Posted April 7, 2009 added this and get no errors <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); ?> Quote Link to comment https://forums.phpfreaks.com/topic/153015-php-update-to-database/#findComment-803684 Share on other sites More sharing options...
Maq Posted April 7, 2009 Share Posted April 7, 2009 Did you get any output for the line I told you to change? Quote Link to comment https://forums.phpfreaks.com/topic/153015-php-update-to-database/#findComment-803685 Share on other sites More sharing options...
sandbudd Posted April 7, 2009 Author Share Posted April 7, 2009 I did add it and it threw no errors Quote Link to comment https://forums.phpfreaks.com/topic/153015-php-update-to-database/#findComment-803686 Share on other sites More sharing options...
revraz Posted April 7, 2009 Share Posted April 7, 2009 echo $sqll You didn't reply to either of my other two questions also. Quote Link to comment https://forums.phpfreaks.com/topic/153015-php-update-to-database/#findComment-803716 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.