Jump to content

Newbie Help with using PHP to update a database


grozanc

Recommended Posts

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" );}
?>

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);

 

 

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' ";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.