Hi All,

Can anybody see why this code wouldnt update the database?

Cheers

Paul

$me = $_SESSION['user_id'];
 $user_title = $_POST['user_title'];
$user_fname = $_POST['user_fname'];
$user_lname = $_POST['user_lname'];
$user_add1 = $_POST['user_add1'];
$user_add2 = $_POST['user_add2'];
$user_city_state = $_POST['user_city_state'];
$user_post_zip = $_POST['user_post_zip'];
$user_email = $_POST['user_email'];
$user_password = $_POST['user_password'];

// Connect to server and select databse.
$conn = mysql_connect("localhost", "un", "pw")or die("cannot connect");
mysql_select_db("db", $conn);
$sql = "UPDATE tbl_user SET user_title = '$user_title',user_fname = '$user_fname',user_lname = '$user_lname',user_add1 = '$user_add1',user_add2 = '$user_add2',user_city_state = '$user_city_state',user_post_zip = '$user_post_zip',user_email = '$user_email',user_password = '$user_password', WHERE user_id = $me";
$result = mysql_query($sql);
echo "thanks";

Recommended Answers

All 4 Replies

I believe you have an extraneous comma before the WHERE in your query, but you don't have any error-checking.

To help correct this, add

if (!$result)
   {
   die("Unable to update table ".mysql_error($conn));
   }

after line 16.

See if that tells you anything. Then report back

take the tick marks off of the variable names. they are being parsed as literal strings.

I too too think you have an extra , after where. Also i think after where has to have ' around $me like this:

WHERE user_id = '$me'"

"UPDATE tbl_user SET user_title = '".$user_title."',user_fname = '".$user_fname."',user_lname = '".$user_lname."',user_add1 = '".$user_add1."',user_add2 = '".$user_add2."',user_city_state = '".$user_city_state."',user_post_zip = '".$user_post_zip."',user_email = '".$user_email."',user_password = '".$user_password."' WHERE user_id = ".$me

Replace your query with the above query. It will work then. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.