PHP executes MySQL statement problem

Source: Internet
Author: User
$id = 1; This is OK, no problem.

This execution is wrong
$sql = "Update admin set pass= ' $pass 1 ' where id= $id;";
$mysql =new mysqlhelper ();
$count = $mysql->query ($sql);
$mysql. Close ();


You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near "at line 1



This execution is correct.
$sql = "Update admin set pass= ' $pass 1 ' where id=1;";
$mysql =new mysqlhelper ();
$count = $mysql->query ($sql);
$mysql. Close ();


Reply to discussion (solution)

Print out $sql and you'll know.

$id = 1; This is OK, no problem.

This execution is wrong
$sql = "Update admin set pass= ' $pass 1 ' where id= $id;";
$mysql =new mysqlhelper ();
$count = $mysql->query ($sql);
$mysql. Close ();



You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near "at line 1



This execution is correct.
$sql = "Update admin set pass= ' $pass 1 ' where id=1;";
$mysql =new mysqlhelper ();
$count = $mysql->query ($sql);
$mysql. Close ();
The red part has a semicolon.

$sql = "Update admin set pass= '". $pass 1. "' where id= $id; '; Change it to this test.

2L positive solution do not need to add a semicolon version of the big say is to solve this kind of problem common approach: query encountered a problem first print out a SQL statement check out nine to ten.

 
  

Tested, and that's really the problem.

Agree to the first floor, print the SQL statement will know

$sql = "Update admin set pass= '". $pass 1. "' Where id= '. $id;

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.