Page 1 of 1

simple mysql query problem

Posted: Tue May 19, 2009 4:01 pm
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!

Re: simple mysql query problem

Posted: Tue May 19, 2009 4:04 pm
by Darhazer
Output the result of mysql_error() after executing the query

Re: simple mysql query problem

Posted: Tue May 19, 2009 4:11 pm
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.