An error occurred while writing data to mysql using form submission.

Source: Internet
Author: User
Form submission connection mysql data writing error for beginners,
Parse error: syntax error, unexpected T_VARIABLE in C: \ AppServ \ www \ form_write_mysql \ add. php on line 7
Line 7
This is the sentence $ SQL = "insert into users (username, email) values ('$ _ POST [username]', '$ _ POST [email]')";
My page is very simple, that is, the form on the login. php page is submitted to add. php, where conn is referenced. Php to connect to mysql

Then, write the data (useranme, email) to the company DB users (username, email) table on mysql.





========================================================== ======================================
Login. php



  

?>

Add. php


Include ("conn. php ");
?>
If (isset ($ _ POST ["submit"]) {
   $ SQL = "insert into users (username, email) values ('$ _ POST [username]', '$ _ POST [email]')";
Mysqli_query ($ conn, $ SQL );
Echo "added successfully ";
}
?>





$ Conn = new mysqli ("localhost", "root", "123123 ");
$ Conn-> select_db ("company ");
// Mysql_query ("set name 'gb2312 '");
$ Conn-> set_charset ("utf8 ");


?>

  


Reply to discussion (solution)

Someone is expecting to answer...

Output the SQL statement to see what it is.
There is no escape. Is it a single quotation mark?

If (isset ($ _ POST ["submit"]) {
$ SQL = "insert into users (username, email) values ('$ _ POST [username]', '$ _ POST [email]')";
Mysqli_query ($ conn, $ SQL );
Echo "added successfully ";
}

Replace the spaces at the front of the rows with English spaces.

$ SQL = "insert into users (username, email) values ('$ _ POST [username]', '$ _ POST [email]')";
Mysqli_query ($ conn, $

The second line of mysql has an I

$ _ POST [username] should be enclosed in quotation marks ===" $ _ POST ['username']. Likewise, email

Print $ SQL to see if the SQL statement is correct.

If (isset ($ _ POST ["submit"]) {
$ SQL = "insert into users (username, email) values ('$ _ POST [username]', '$ _ POST [email]')";
Mysqli_query ($ conn, $ SQL );
Echo "added successfully ";
}

Replace the spaces at the front of the rows with English spaces.


Guoran nb
Fatal error: Call to undefined function when creating writable tables include () in C: \ AppServ \ www \ form_write_mysql \ add. php on line 3
Hehe queshi zhege yuanying

$ Conn = new mysqli ("localhost", "root", "123123"); $ conn-> select_db ("company "); // mysql_query ("set name 'gb2312 '"); $ conn-> set_charset ("utf8 ");
Warning: mysqli_query () expects parameter 1 to be mysqli, null given in C: \ AppServ \ www \ form_write_mysql \ add. php on line 8
Added


In fact, this $ conn is used correctly, but I am adding it. Php
Echo $ conn .'
';
But no output results. why?
@ Jordan102

Include ("conn. php ");
?>

There are spaces in the front of include.
Since the database is connected in the object-oriented way, why not execute SQL in the object-oriented way.
$ Conn-> query ($ SQL );

The MySQL statement in add. php is incorrect. The original statement mysqli_query ($ con you, change to mysql_query ($ con you,

It's not closed yet.

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.