Why does this SQL statement always fail?

Source: Internet
Author: User
Why does this SQL statement always fail?
$idinfo =mysql_fetch_array ("select * from Tb_yonghu where name= ' $name ' and id= ' $id '") or Die ("Access failed");

Is the statement itself a problem? Is there any relationship between $name and $id plus single quotes?

In front of Echo $name and $id both have values and are the same as the values in the database
Why do I always show access failures?
The database connection should be fine because the database link fails if there is a problem

------Solution--------------------
Die ("Access Failed") indicates that "Access failed" is displayed as long as the mysql_fetch_array execution is unsuccessful, so you cannot conclude that there is no problem with the database connection.
------Solution--------------------
Look at the manual, Mysql_fetch_array is the execution resource, not the statement.
PHP Code
$rs =mysql_query ("select * from Tb_yonghu where name= ' $name ' and id= ' $id '") or Die ("Access failed"); $idinfo =mysql_fetch_array ($RS);
------Solution--------------------
The function to execute SQL is mysql_query (), your own first officer nets the next php_manual to see ripe.
------Solution--------------------

Manual to carry ...
  • Related Article

    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.