sandbudd Posted June 12, 2009 Share Posted June 12, 2009 Displays the information from the database. When update is clicked it does display the correct id but when I make changes it does not update the database? Please help. Here is the file that displays the correct info but when click submit it does not update the database. <?php // Connect database. $host=""; $db_user=""; $db_password=""; $database=""; mysql_connect($host,$db_user,$db_password); mysql_select_db($database); // ***** This part will process when you Click on "Submit" button ***** // Check, if you clicked "Submit" button if($_POST['Submit']){ $id=$_POST['id']; $name=$_POST['name']; $email=$_POST['email']; $bday_month=$_POST['bday_month']; $bday_day=$_POST['bday_day']; $ann_month=$_POST['ann_month']; $ann_day=$_POST['ann_day']; $address=$_POST['address']; $city=$_POST['city']; $state=$_POST['state']; $zip=$_POST['zip']; $favorite=$_POST['favorite']; $lunch=$_POST['lunch']; $reservations=$_POST['reservations']; $parties=$_POST['parties']; $new_menu=$_POST['new_menu']; $chef_specials=$_POST['chef_specials']; // Do update statement. mysql_query("update mastodon set name='$name', email='$email', bday_month='$bday_month', bday_day='$bday_day', ann_month='$ann_month', ann_day='$ann_day', address='$address', city='$city', state='$state', zip='$zip', favorite='$favorite', lunch='$lunch', reservations='$reservations', parties='$parties', new_menu='$new_menu', chef_specials='$chef_specials' where id='$id'"); // Re-direct this page. header("location:update.php"); exit; } // ************* End update part ************* // *** Select data to show on text fields in form. *** // Get id parameter (GET method) $id=$_GET['id']; // Get records in all columns from table where column id equal in $id and put it in $result. $result=mysql_query("select * from mastodon where id='$id'"); // Split records in $result by table rows and put them in $row. $row=mysql_fetch_assoc($result); // Close database connection. mysql_close(); ?> <!-- END OF PHP CODES AND START HTML TAGS --> <html> <body> <!-- set this form to POST method and target this form to itself ($PHP_SELF;)--> <form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>"> <table width="707" border="1" cellpadding="3" cellspacing="0" class="appfields"> <tr> <td width="42%"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Member </span></td> <td width="58%"><input name="name<? echo $row['id']; ?>" type="text" id="name<? echo $row['id']; ?>" value="<? echo $row['name']; ?>" size="50" /></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Email Address<br> </span></td> <td><input name="email" type="text" id="email" value="<? echo $row['email']; ?>"/></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Birthday<strong><br> </strong></span></td> <td><strong> <input name="bday_month" type="text" id="bday_month" value="<? echo $row['bday_month']; ?>"/> <input name="bday_day" type="text" id="bday_day" value="<? echo $row['bday_day']; ?>"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Anniversary<strong><br> </strong></span></td> <td><strong> <input name="ann_month" type="text" id="ann_month" value="<? echo $row['ann_month']; ?>"/> <input name="ann_day" type="text" id="ann_day" value="<? echo $row['ann_day']; ?>"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Address<br> </span></td> <td><strong> <input name="address" type="text" id="address" value="<? echo $row['address']; ?>"/> </strong></td> </tr> <tr> <td><br></td> <td><strong> <input name="city" type="text" id="city" value="<? echo $row['city']; ?>"/> , <input name="state" type="text" id="state" value="<? echo $row['state']; ?>" size="4"/> <input name="zip" type="text" id="zip" value="<? echo $row['zip']; ?>" size="10"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14"> <label for="favorite">Favorite Menu Items</label> </span></td> <td><strong> <input name="favorite" type="text" id="favorite" value="<? echo $row['favorite']; ?>" size="60"/> </strong></td> </tr> <tr> <td colspan="2"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">I am interested in information:</span></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14"> <label for="lunch">Lunch & Dinner Specials</label> </span></td> <td><strong> <input name="lunch" type="text" id="lunch" value="<? echo $row['lunch']; ?>" size="4"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14"> <label for="reservations">Reservations</label> </span></td> <td><strong> <input name="reservations" type="text" id="reservations" value="<? echo $row['reservations']; ?>" size="4"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Large Parties or Groups</span></td> <td><strong> <input name="parties" type="text" id="parties" value="<? echo $row['parties']; ?>" size="4"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">New Menu Selections</span></td> <td><strong> <input name="new_menu" type="text" id="new_menu" value="<? echo $row['new_menu']; ?>" size="4"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Our Chef's Specials</span></td> <td><strong> <input name="chef_specials" type="text" id="chef_specials" value="<? echo $row['chef_specials']; ?>" size="4"/> </strong></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> <p> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Alex Posted June 12, 2009 Share Posted June 12, 2009 Try: mysql_query('update mastodon set name="' . $name . '", email="' . $email . '", bday_month="' . $bday_month . '", bday_day="' . $bday_day . '", ann_month="' . $ann_month . '", ann_day="' . $ann_day . '", address="' . $address . '", city="' . $city . '", state="' . $state . '", zip="' . $zip . '", favorite="' . $favorite . '", lunch="' . $lunch . '", reservations="' . $reservations . '", parties="' . $parties . '", new_menu="' . $new_menu . '", chef_specials="' . $chef_specials . '" where id="' . $id . '"'); Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 12, 2009 Author Share Posted June 12, 2009 get a blank page with no errors? Quote Link to comment Share on other sites More sharing options...
Alex Posted June 12, 2009 Share Posted June 12, 2009 get a blank page with no errors? There was a problem with my query. I forgot a '.' try it now. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 12, 2009 Author Share Posted June 12, 2009 changed to this it is displays but still does not update database? <?php mysql_query('update mastodon set name="' . $name . '", email="' . $email . '", bday_month="' . $bday_month . '", bday_day="' . $bday_day . '", ann_month="' . $ann_month . '", ann_day="' . $ann_day . '", address="' . $address . '", city="' . $city . '", state="' . $state . '", zip="' . $zip . '", favorite="' . $favorite . '", lunch="' . $lunch . '", reservations="' . $reservations . '", parties="' . $parties . '", new_menu="' . $new_menu .'", chef_specials="' . $chef_specials . '" where id="' . $id . '"'); ?> Quote Link to comment Share on other sites More sharing options...
Alex Posted June 12, 2009 Share Posted June 12, 2009 The query looks fine to me. Try this to debug it: mysql_query('update mastodon set name="' . $name . '", email="' . $email . '", bday_month="' . $bday_month . '", bday_day="' . $bday_day . '", ann_month="' . $ann_month . '", ann_day="' . $ann_day . '", address="' . $address . '", city="' . $city . '", state="' . $state . '", zip="' . $zip . '", favorite="' . $favorite . '", lunch="' . $lunch . '", reservations="' . $reservations . '", parties="' . $parties . '", new_menu="' . $new_menu .'", chef_specials="' . $chef_specials . '" where id="' . $id . '"') or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
tom2oo8 Posted June 12, 2009 Share Posted June 12, 2009 offtopic(sorry): I dont get why every one uses all that dot stuff in the querys doesnt: mysql_query("update mastodon set name='$name' ") or die(mysql_error()); work the same as: mysql_query('update mastodon set name="' . $name . '" ') or die(mysql_error()); except the way you do it is longer and gets me confused, (unless its some sort of security issue?) Any way your query looks correct to me but ill look further in to it may just be a small error Quote Link to comment Share on other sites More sharing options...
tom2oo8 Posted June 12, 2009 Share Posted June 12, 2009 Can i ask , have you tried making it not redirect to updated.php so you can see the error Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 12, 2009 Author Share Posted June 12, 2009 took out the redirect blank page on submit no errors Quote Link to comment Share on other sites More sharing options...
tom2oo8 Posted June 12, 2009 Share Posted June 12, 2009 took out the redirect blank page on submit no errors I uploded the file to my server and it doesnt work either , not sure why and theres no errors :S Quote Link to comment Share on other sites More sharing options...
tom2oo8 Posted June 12, 2009 Share Posted June 12, 2009 Actually have you thought of changing $id= $_POST['id']; to $id= $_GET['id']; as its not getting the id from any where ANd it works on my server now Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 12, 2009 Author Share Posted June 12, 2009 changed and it still did not update the db and threw no errors Quote Link to comment Share on other sites More sharing options...
tom2oo8 Posted June 12, 2009 Share Posted June 12, 2009 changed and it still did not update the db and threw no errors whats a link to your site? also <input name="name<? echo $row['id']; ?>" type="text" id="name<? echo $row['id']; ?>" value="<? echo $row['name']; ?> Whats that all about? that wont work as above you have $name as just $_POST['name']; and not name<idhere> as you can see it works on my server , did a lil adapting but yer: http://biz-e-allotments.com/pleasedowork.php?id=3 <?php // Connect database. $host="localhost"; $db_user=""; $db_password=""; $database=""; mysql_connect($host,$db_user,$db_password); mysql_select_db($database); // ***** This part will process when you Click on "Submit" button ***** // Check, if you clicked "Submit" button if($_GET['page'] == "update") { $id=$_GET['id']; $name=$_POST['name']; $email=$_POST['email']; $bday_month=$_POST['bday_month']; $bday_day=$_POST['bday_day']; $ann_month=$_POST['ann_month']; $ann_day=$_POST['ann_day']; $address=$_POST['address']; $city=$_POST['city']; $state=$_POST['state']; $zip=$_POST['zip']; $favorite=$_POST['favorite']; $lunch=$_POST['lunch']; $reservations=$_POST['reservations']; $parties=$_POST['parties']; $new_menu=$_POST['new_menu']; $chef_specials=$_POST['chef_specials']; // Do update statement. mysql_query("update help set name='$name', email='$email', bday_month='$bday_month', bday_day='$bday_day', ann_month='$ann_month', ann_day='$ann_day', address='$address', city='$city', state='$state', zip='$zip', favorite='$favorite', lunch='$lunch', reservations='$reservations', parties='$parties', new_menu='$new_menu', chef_specials='$chef_specials' where id='$id'") or die(mysql_error()); } // ************* End update part ************* // *** Select data to show on text fields in form. *** // Get id parameter (GET method) $id=$_GET['id']; // Get records in all columns from table where column id equal in $id and put it in $result. $result=mysql_query("select * from help where id='$id'"); // Split records in $result by table rows and put them in $row. $row=mysql_fetch_assoc($result); // Close database connection. mysql_close(); ?> <!-- END OF PHP CODES AND START HTML TAGS --> <html> <body> <!-- set this form to POST method and target this form to itself ($PHP_SELF;)--> <form id="form1" name="form1" method="post" action="?id=3&page=update"> <table width="707" border="1" cellpadding="3" cellspacing="0" class="appfields"> <tr> <td width="42%"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Member </span></td> <td width="58%"><input name="name" type="text" id="name" value="<? echo $row['name']; ?>" size="50" /></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Email Address<br> </span></td> <td><input name="email" type="text" id="email" value="<? echo $row['email']; ?>"/></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Birthday<strong><br> </strong></span></td> <td><strong> <input name="bday_month" type="text" id="bday_month" value="<? echo $row['bday_month']; ?>"/> <input name="bday_day" type="text" id="bday_day" value="<? echo $row['bday_day']; ?>"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Anniversary<strong><br> </strong></span></td> <td><strong> <input name="ann_month" type="text" id="ann_month" value="<? echo $row['ann_month']; ?>"/> <input name="ann_day" type="text" id="ann_day" value="<? echo $row['ann_day']; ?>"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Address<br> </span></td> <td><strong> <input name="address" type="text" id="address" value="<? echo $row['address']; ?>"/> </strong></td> </tr> <tr> <td><br></td> <td><strong> <input name="city" type="text" id="city" value="<? echo $row['city']; ?>"/> , <input name="state" type="text" id="state" value="<? echo $row['state']; ?>" size="4"/> <input name="zip" type="text" id="zip" value="<? echo $row['zip']; ?>" size="10"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14"> <label for="favorite">Favorite Menu Items</label> </span></td> <td><strong> <input name="favorite" type="text" id="favorite" value="<? echo $row['favorite']; ?>" size="60"/> </strong></td> </tr> <tr> <td colspan="2"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">I am interested in information:</span></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14"> <label for="lunch">Lunch & Dinner Specials</label> </span></td> <td><strong> <input name="lunch" type="text" id="lunch" value="<? echo $row['lunch']; ?>" size="4"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14"> <label for="reservations">Reservations</label> </span></td> <td><strong> <input name="reservations" type="text" id="reservations" value="<? echo $row['reservations']; ?>" size="4"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Large Parties or Groups</span></td> <td><strong> <input name="parties" type="text" id="parties" value="<? echo $row['parties']; ?>" size="4"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">New Menu Selections</span></td> <td><strong> <input name="new_menu" type="text" id="new_menu" value="<? echo $row['new_menu']; ?>" size="4"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Our Chef's Specials</span></td> <td><strong> <input name="chef_specials" type="text" id="chef_specials" value="<? echo $row['chef_specials']; ?>" size="4"/> </strong></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> <p> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 12, 2009 Author Share Posted June 12, 2009 Tom let me pm you as it is a populated database Quote Link to comment Share on other sites More sharing options...
tom2oo8 Posted June 13, 2009 Share Posted June 13, 2009 Tom let me pm you as it is a populated database ok, but read my post above as it works Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 13, 2009 Author Share Posted June 13, 2009 go ahead and try and modify one of them and you will see what is happening Quote Link to comment Share on other sites More sharing options...
tom2oo8 Posted June 13, 2009 Share Posted June 13, 2009 go ahead and try and modify one of them and you will see what is happening i have and it doesnt but i can also tell that you havent updated your script like i said above in my new edit http://www.phpfreaks.com/forums/index.php/topic,256373.msg1205773.html#msg1205773 Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 13, 2009 Author Share Posted June 13, 2009 will do give me a sec and thanks for all your help Quote Link to comment Share on other sites More sharing options...
tom2oo8 Posted June 13, 2009 Share Posted June 13, 2009 will do give me a sec and thanks for all your help np Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 13, 2009 Author Share Posted June 13, 2009 now you can see what happens Quote Link to comment Share on other sites More sharing options...
tom2oo8 Posted June 13, 2009 Share Posted June 13, 2009 Oh crap forgot to metion Change the table "help" to your table on your database Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 13, 2009 Author Share Posted June 13, 2009 changed back table and still it is not showing Quote Link to comment Share on other sites More sharing options...
tom2oo8 Posted June 13, 2009 Share Posted June 13, 2009 changed back table and still it is not showing both? theres two instances Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 13, 2009 Author Share Posted June 13, 2009 yes and it is showing the correct ID in the URL Quote Link to comment Share on other sites More sharing options...
tom2oo8 Posted June 13, 2009 Share Posted June 13, 2009 yes and it is showing the correct ID in the URL put your code here of your page and i see why: Quote Link to comment 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.