Using php to insert data can only insert numbers and letters, but cannot insert texts.-php Tutorial

Source: Internet
Author: User
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.

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.