grozanc Posted March 6, 2008 Share Posted March 6, 2008 Can anyone see what I'm doing wrong? The form (not displayed) pulls the already existing data properly but it doesn't save the changes to the database and doesn't redirect with the variables I set. The $thanks variable gets lost, but the $first_name variable gets carried. Any advice? Thanks, Gary! <?php $host = 'localhost'; $user = 'xxxxxx'; $pass = 'xxxxxx'; $db = 'xxxxxx'; mysql_connect($host,$user,$pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); // Set variables $id=$_GET['id']; $first_name = $_POST['first_name']; $email = $_POST['email']; $city = $_POST['city']; $state = $_POST['state']; $link = $_POST['link']; $story = $_POST['story']; $thanks = $_POST['5']; // Insert into database $query = "UPDATE uploads_content SET first_name = '$first_name', email = '$email', city = '$city', state = '$state', link = '$link', story = '$story', approved = '0' WHERE 'id' = '$id' "; mysql_query($query) or die('Error, query failed : ' . mysql_error()); // Page Redirect if($query) {header( "Location: http://www.pavementmemories.com/thanks.php?first_name=$first_name&thanks=$thanks" );} else {header( "Location: http://www.pavementmemories.com/oops_contact.php" );} ?> Link to comment https://forums.phpfreaks.com/topic/94615-newbie-help-with-using-php-to-update-a-database/ Share on other sites More sharing options...
matto Posted March 6, 2008 Share Posted March 6, 2008 The think the reason it's not updating the database is you are using a combination of $_POST & $_GET maybe this line $id=$_GET['id']; s/be $id=$_POST['id']; You should try debugging this by adding this line to the top of the page print_r($_POST); Link to comment https://forums.phpfreaks.com/topic/94615-newbie-help-with-using-php-to-update-a-database/#findComment-484509 Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 on WHERE 'id'= '$id' change it to `id` = '{$id}' Link to comment https://forums.phpfreaks.com/topic/94615-newbie-help-with-using-php-to-update-a-database/#findComment-484511 Share on other sites More sharing options...
grozanc Posted March 6, 2008 Author Share Posted March 6, 2008 Thanks for the help so far. I tried both of the suggestions and neither worked. When I printed the posts, all the information was posted except for the $thanks variable. Any other suggestions? Link to comment https://forums.phpfreaks.com/topic/94615-newbie-help-with-using-php-to-update-a-database/#findComment-484527 Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 go back to the scipt that was the form that users entered info into. check to see the name of the text field of "thanks" matches "5" Link to comment https://forums.phpfreaks.com/topic/94615-newbie-help-with-using-php-to-update-a-database/#findComment-484534 Share on other sites More sharing options...
grozanc Posted March 6, 2008 Author Share Posted March 6, 2008 Thanks, I found the mistake that wasn't letting the $thanks variable pass through, however, I still can't get this to update the information in the database! The variables are posting, just not getting updated in the database. Link to comment https://forums.phpfreaks.com/topic/94615-newbie-help-with-using-php-to-update-a-database/#findComment-484538 Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 i don;'t thin kthis will matter, but try it... $query = "UPDATE `uploads_content` SET `first_name` = '$first_name', `email` = '$email', `city` = '$city', `state` = '$state', `link` = '$link', `story` = '$story', `approved` = '0' WHERE `id` = '$id' "; Link to comment https://forums.phpfreaks.com/topic/94615-newbie-help-with-using-php-to-update-a-database/#findComment-484547 Share on other sites More sharing options...
revraz Posted March 6, 2008 Share Posted March 6, 2008 echo $query to validate the string Link to comment https://forums.phpfreaks.com/topic/94615-newbie-help-with-using-php-to-update-a-database/#findComment-484552 Share on other sites More sharing options...
grozanc Posted March 6, 2008 Author Share Posted March 6, 2008 Thanks Everyone! The last comment solved the problem. The $id variable wasn't being passed from the form properly. Now that I fixed that everything works fine! Link to comment https://forums.phpfreaks.com/topic/94615-newbie-help-with-using-php-to-update-a-database/#findComment-484562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.