PHP UPDATE code

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jtb29
Forum Newbie
Posts: 1
Joined: Sat Feb 07, 2009 9:37 pm

PHP UPDATE code

Post by jtb29 »

Hey I'm new to PHP and MySQL, and I've looked over a few codes for UPDATE, but no matter what I change my code to, it just will NOT work. I will post my code below. Any suggestions would be EXTREMELY appreciated! Thanks!

Code: Select all

 
<?php
$con = mysql_connect("localhost","Website","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("website", $con);
 
mysql_query("UPDATE users u SET u.Password = 'Password', u.First_Name = 'First_Name', u.Middle_Initial = 'Middle_Initial', u.Last_Name = 'Last_Name', u.Street_Address = 'Street_Address', u.City_Town = 'City_Town', u.Province = 'Province', u.Postal_Zip = 'Postal_Zip', u.Activities = 'Activities', u.Animals_Pets = 'Animals_Pets', u.Cars = 'Cars', u.Movies = 'Movies', u.Music = 'Music', u.Outdoor = 'Outdoor', u.Sports = 'Sports', u.Video_Games = 'Video_Games'
WHERE User_Id = '$_SESSION['Email1']'");
 
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record updated";
 
mysql_close($con);
?>
 
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: PHP UPDATE code

Post by susrisha »

there is no variable defined by name $sql in your code. either assign the query statement to the $sql or give the resource link the mysql_query statement.

Code: Select all

 
mysql_query("UPDATE users u SET u.Password = 'Password', u.First_Name = 'First_Name', u.Middle_Initial = 'Middle_Initial', u.Last_Name = 'Last_Name', u.Street_Address = 'Street_Address', u.City_Town = 'City_Town', u.Province = 'Province', u.Postal_Zip = 'Postal_Zip', u.Activities = 'Activities', u.Animals_Pets = 'Animals_Pets', u.Cars = 'Cars', u.Movies = 'Movies', u.Music = 'Music', u.Outdoor = 'Outdoor', u.Sports = 'Sports', u.Video_Games = 'Video_Games'
WHERE User_Id = '$_SESSION['Email1']'",$con);
//always give the resource link when you are trying to update or insert the data into mysql.
 
Post Reply