simple mysql query problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rbroadwe
Forum Newbie
Posts: 10
Joined: Wed May 06, 2009 5:18 pm

simple mysql query problem

Post by rbroadwe »

Code: Select all

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
 
$sql = 'UPDATE appt
        SET fname = "$fname", lname = "$lname", street = "$street", zip = "$zip", phone = "$phone", problem = "$problem", booked = "Y"
        WHERE id="$id"';
 
mysql_select_db("robbroa1_fox", $con);
$retval = mysql_query( $sql, $con );
if(! $retval )
{
  die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($con);
it doesn't error but it doesn't update the rows and I dont know why. Does anyone see the problem? Thank you!
Last edited by Benjamin on Tue May 19, 2009 4:26 pm, edited 2 times in total.
Reason: Changed code type from text to php.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: simple mysql query problem

Post by Darhazer »

Output the result of mysql_error() after executing the query
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: simple mysql query problem

Post by Benjamin »

More than likely one or more of the variables used in the query contain a '. You'll need to (and you should be), using mysql_real_escape_string() to ensure that your application works and is secure from SQL injection.
Post Reply