harkly Posted December 18, 2008 Share Posted December 18, 2008 I am trying to update my database but it wont work - not getting any errors either. I am pulling the info into a form on one page and then passing it to another. Page 1 mysql_select_db("artdb"); $search=$_GET["artid"]; //pulls info for Artist $result = mysql_query("SELECT * FROM artist WHERE artid = '$search'"); while ($r=mysql_fetch_array($result)) { $fullName=$r["fullName"]; $artid=$r["artid"]; //display the row echo "<tr><td><form method=\"get\" action='artist3.php'></td></tr>\n"; echo "<input type=\"hidden\" name=\"artid\" value=\"$artid\"></td></tr>\n"; echo "<tr><td><h3>Art Id</h3></td><td><input type=\"text\" name=\"artid\" value=\"$artid\"></td></tr>\n"; echo "<tr><td><h3>Full Name</h3></td><td><input type=\"text\" name=\"fullName\" value=\"$fullName\"></td></tr>\n"; echo "<tr><td><input type=\"submit\" name=\"button\" value=\"Update\"></td></tr>\n"; echo "</form>\n"; } passes to this page mysql_select_db("artdb"); $search=$_GET["artid"]; $fullName=$_GET["fullName"]; $artid=$r["artid"]; echo "<table width=950 border=1 align=center>"; echo " <tr>"; echo " <td width=200>";echo " </td>"; echo " <td width=600>"; //pulls info for Artist $result = mysql_query("UPDATE artist SET fullName ='$fullName' WHERE artid ='$artid'"); if(!$result){ echo " Unable to update your contacts";}else{echo "Your contacts updated successfuly";} ?> I get the msg that it has been updated. Link to comment https://forums.phpfreaks.com/topic/137464-solved-updating-database/ Share on other sites More sharing options...
redarrow Posted December 18, 2008 Share Posted December 18, 2008 your posting from a form to update not getting a variable from a url... look at your second posted code.... Link to comment https://forums.phpfreaks.com/topic/137464-solved-updating-database/#findComment-718375 Share on other sites More sharing options...
twm Posted December 18, 2008 Share Posted December 18, 2008 on the second page change $artid=$r["artid"]; to $artid=$_GET["artid"]; Link to comment https://forums.phpfreaks.com/topic/137464-solved-updating-database/#findComment-718384 Share on other sites More sharing options...
mmarif4u Posted December 18, 2008 Share Posted December 18, 2008 The best thing here is to echo your variables in 2nd page, that either they are holding any data or not. And also this is wrong: $artid=$r["artid"]; Link to comment https://forums.phpfreaks.com/topic/137464-solved-updating-database/#findComment-718385 Share on other sites More sharing options...
harkly Posted December 18, 2008 Author Share Posted December 18, 2008 I changed the code but still no go.. Also looks like its not passing the info - checked with echo ".$fullName."; mysql_select_db("artdb"); $search=$_GET["artid"]; //pulls info for Artist $result = mysql_query("SELECT * FROM artist WHERE artid = '$search'"); while ($r=mysql_fetch_array($result)) { $fullName=$r["fullName"]; $artid=$r["artid"]; //display the row echo "<tr><td><form method=\"post\" action='artist3.php'></td></tr>\n"; echo "<input type=\"hidden\" name=\"artid\" value=\"$artid\"></td></tr>\n"; echo "<tr><td><h3>Art Id</h3></td><td><input type=\"text\" name=\"artid\" value=\"$artid\"></td></tr>\n"; echo "<tr><td><h3>Full Name</h3></td><td><input type=\"text\" name=\"fullName\" value=\"$fullName\"></td></tr>\n"; echo "<tr><td><input type=\"submit\" name=\"update\" value=\"Update\"></td></tr>\n"; echo "</form>\n"; } mysql_select_db("artdb"); $search=$_Post["update"]; $fullName=$_Post["fullName"]; $artid=$_Post["artid"]; //pulls info for Artist $query = "UPDATE artist SET fullName = '$fullName' WHERE artid = '$artid' "; $result = mysql_query($query) or die(mysql_error()); if ($result) { echo "<h2>Information changed.</h2>\n"; } else { echo "<h2>Sorry, I could not change the information.</h2>\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/137464-solved-updating-database/#findComment-718390 Share on other sites More sharing options...
twm Posted December 18, 2008 Share Posted December 18, 2008 $_POST is all caps , you have $_Post Link to comment https://forums.phpfreaks.com/topic/137464-solved-updating-database/#findComment-718392 Share on other sites More sharing options...
harkly Posted December 18, 2008 Author Share Posted December 18, 2008 Thanks!! Was pulling my hair out over CAPS! Link to comment https://forums.phpfreaks.com/topic/137464-solved-updating-database/#findComment-718395 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.