简体   繁体   中英

why am I getting Error: Query was empty?

I am getting this error when I try to use the following code! I don't understand the reason. I assume its something to do with the UPDATE but i dont get what it is!

<?php
$con = mysql_connect("localhost","","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("", $con);

mysql_query("UPDATE pages SET pagebody = 'firstname'");

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con);
?>

You don't select database here mysql_select_db("[db name]", $con); . And another thing, are you planning to update all entries in the pages table? Because you don't have a WHERE clause. The comments here have their points though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM