Why is mysql_fetch_array not executed?

Source: Internet
Author: User
error_reporting (0);
$conn =mysql_connect ("localhost", "root", "root");//fill in the database connection information
mysql_select_db ("a1209173000");//fill in the database name
$valA = $_post["ValA"];
if ($valA! = "") {
$sql = "SELECT * from table where chepai= '". $valA. "'";
$result =mysql_query ($sql);
while ($arr =mysql_fetch_array ($result))
{
echo $arr ["name"]. "
";
}
}else{
?>

}
?>

By adding the echo output at the back of each line, the discovery executes to the while ($arr =mysql_fetch_array ($result)) when there is no execution, what's wrong, $sql normal


Reply to discussion (solution)

You are not taking $vala = $_post["ValA"]; this value

$result =mysql_query ($sql), if (Mysql_error ()) {  echo Mysql_errno (). ": " . Mysql_error (). "\ n";}

See if there's an error?

$result =mysql_query ($sql), if (Mysql_error ()) {  echo Mysql_errno (). ": " . Mysql_error (). "\ n";}

See if there's an error?

Sure is.
1064:you has an error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near '?? AUQ005 ' at line 1
I entered the text box in the Chinese characters, the result was garbled, but Echo $valA, the result is Yu AUQ005.  Is this the reason why the page code is not set? How does PHP set

$valA is right, echo $sql There is nothing wrong, but when it is executed, the Chinese character is wrong

You are not taking $vala = $_post["ValA"]; this value

Thank you, according to Mumubangditu method, found that I entered the conditions of Chinese characters, and the Chinese character has not been successfully identified, how to solve AH.

In
mysql_select_db ("a1209173000");//fill in the database name
After that, join
mysql_query (' Set names GBK ');
This is caused by inconsistencies between the data being manipulated and the default character set of the database

In
mysql_select_db ("a1209173000");//fill in the database name
After that, join
mysql_query (' Set names GBK ');
This is caused by inconsistencies between the data being manipulated and the default character set of the database

Thank you moderator, solve the

  • 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.