Using php to insert data can only insert numbers and letters, but cannot insert text. I first use $ _ POST to obtain the two data in the form and then submit the data to the page where SQL statements are executed, but the data cannot be inserted all the time. ++ ++ ++ & nbsp; & lt ;? Php & nbsp; require & quot; 777.php& quot; & nbs use php to insert data. only numbers and letters can be inserted without text.
I first use $ _ POST to get the two data in the form and then submit the data to the page where the SQL statement is executed, but the text cannot be inserted all the time.
++ ++
Require "777.php ";
Mysql_query ("set names 'utf-8 ");
Mysql_query ("set names 'gb2312 '");
$ SQL = mysql_query ("select * from lyb"); // output the message content
While ($ sq = mysql_fetch_array ($ SQL )){
Echo $ sq [id];
}
?>
= ++ ++
/*
* Created on 2012-4-3
*
* To change the template for this generated file go
* Window-Preferences-PHPeclipse-PHP-Code Templates
*/
Require "777.php ";
If ($ _ POST [submit]! = ""){
$ User = $ _ POST [user];
$ Post = $ _ POST ["intro"];
$ SQL = "insert into lyb (user, post) values ('$ user',' $ Post')"; // execute the SQL insert statement page
$ Qu = mysql_query ($ SQL );
If ($ qu ){
Echo 'View message ';
}
}
?>
++ ++
$ Db = "localhost ";
$ User = "root ";
$ Pwd = "123456 ";
$ Conn = mysql_connect ("$ db", "$ user", "$ pwd ");
Mysql_select_db ("sjk", $ conn );
?>
++ ++
------ Solution --------------------
Is your first code output? What can be seen?
Mysql_query ("set names 'utf-8 ");
Should be
Mysql_query ("set names 'utf8 ");
If your program file is UTF-8 encoded, use
Mysql_query ("set names 'utf8 ");
If your program file is gbk encoded, use
Mysql_query ("set names 'gb2312 '");
Preferably
Mysql_query ("set names 'gbk '");
Select one
The second part of the code has no language declaration. even if it is inserted, it may be garbled.
$ SQL = "insert into lyb (user, post) values ('$ user',' $ Post ')";
$ Qu = mysql_query ($ SQL) or die (mysql_error ());
Let's take a look at all the errors.