An error occurred while inserting php Data into MYSQL. how can this problem be correctly inserted?

Source: Internet
Author: User
An error occurred while inserting php Data into MYSQL. how can I insert the data correctly? // The php code is as follows: & lt ;? Php // UseInsert. php & nbsp; functiongetDatabase () {& nbsp; $ l an error occurred while inserting php Data into MYSQL. how can this problem be correctly inserted?
// The php code is as follows:


// UseInsert. php
Function getDatabase (){
$ Link = mysql_connect ("localhost", "root", "mysql"); // connect to the server
Mysql_query ("set character set GB2312"); // The database data is stored in gb2312
If ($ link) {// connection to the server successful
$ Db = "studentdata"; // select a database
If (! Mysql_select_db ($ db, $ link) echo "select database". $ db. "failed
";
Else echo "select database". $ db. "successful
";
}
Else echo "failed to connect to the server". mysql_error ();
}
// Insert data
GetDatabase ();
Mysql_query ("set names GB2312 ");
$ ReadSelect = mysql_query ("select * from student ");
$ Array = mysql_fetch_array ($ readSelect, MYSQL_ASSOC );
For (; $ array = mysql_fetch_array ($ readSelect, MYSQL_ASSOC )){
Echo $ array ['id']. "". $ array ['name']."
";
}
USD id = "1234123 ";
$ Name = "Zhang Xueshu ";
$ Insert = "INSERT ignore into student ('id', 'name') values ($ id, $ name )";
Mysql_query ($ insert) or die ("
Insertion failed ". mysql_error ());

?>

// Webpage output:
Database studentdata selected successfully
1110009999 Li Si
1110009997 Zhang San
1110009996 Wang Wu

Insertion failed 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 ''id', 'name ') values (1234123, Zhang Xuezhen) 'at line 1



How can I insert data correctly?

------ Solution --------------------
$ Insert = "INSERT ignore into student ('id', 'name') values ($ id, '$ name ')";

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.