Php execution of mysql statements

Source: Internet
Author: User
Php execution of mysql statement $ id = 1; & nbsp; this is OK, this execution error $ SQL = "update & nbsp; admin & nbsp; set & nbsp; pass = '$ pass1' & nbsp; where & nbsp; id = $ id; "; $ mysql = new & nbsp; MysqlHelper (); $ count php execution of mysql statements
$ Id = 1; this is OK

This execution is incorrect.
$ SQL = "update admin set pass = '$ pass1' where id = $ id ;";
$ Mysql = new MysqlHelper ();
$ Count = $ mysql-> query ($ SQL );
$ Mysql. close ();


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''at line 1



This execution is correct.
$ SQL = "update admin set pass = '$ pass1' where id = 1 ;";'
$ Mysql = new MysqlHelper ();
$ Count = $ mysql-> query ($ SQL );
$ Mysql. close ();
Share:
------ Solution --------------------
Print $ SQL.
------ Solution --------------------
Reference:
$ Id = 1; this is OK

This execution is incorrect.
$ SQL = "update admin set pass = '$ pass1' where id = $ id ;";
$ Mysql = new MysqlHelper ();
$ Count = $ mysql-> query ($ SQL );
$ Mysql. close ();



You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''at line 1



This execution is correct.
$ SQL = "update admin set pass = '$ pass1' where id = 1 ;";'
$ Mysql = new MysqlHelper ();
$ Count = $ mysql-> query ($ SQL );
$ Mysql. close ();

The red part has a semicolon.
------ Solution --------------------
$ SQL = "update admin set pass = '". $ pass1. "'Where id = $ id;"; use this command.
------ Solution --------------------
2L positive solutions do not need to be added. what we talk about is the common solution to this problem: when a query encounters a problem, print the SQL statement and check it out ./
------ Solution --------------------

$pass1="123";
$id=1;
    $sql="update admin set pass='".$pass1."' where id=$id;";
echo $sql;
?>

This is a real problem after testing.
------ Solution --------------------
$ SQL = "update admin set pass = '". $ pass1. "'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.