Insert data in PHP can only insert numbers and letters cannot be inserted into the text solution

Source: Internet
Author: User
Insert data in PHP can only insert numbers and letters can't insert text
I first used $_post to get two of the form's data and then submit it to the page that executed the SQL statement, but I always couldn't insert the text.
+++++++++++++++++++++++++++++++++++++++++++++++++++++
Require "777.php";
mysql_query ("Set names ' Utf-8");
mysql_query ("SET NAMES ' GB2312 '");
$sql = mysql_query ("Select*from lyb"); Output 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 to
* 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 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--------------------
Does your first piece of code have output? What can you see?
mysql_query ("Set names ' Utf-8");
should be for
mysql_query ("Set names ' UTF8");

If your program file is UTF-8 encoded, use the
mysql_query ("Set names ' UTF8");
If your program file is GBK encoded, use the
mysql_query ("SET NAMES ' GB2312 '");
Better be
mysql_query ("SET NAMES ' GBK '");

Choose one of the two

The second piece of code does not have a 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 ());
See what's wrong with the report.
  • 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.