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.