Sunday Disturb everybody, really embarrassed, but really is anxious about MySQL's related question

Source: Internet
Author: User
Sunday Disturb everybody, really embarrassed, but really is anxious ah ... The question about MySQL
PHP Code
  
     $query =mysql_query ("select * from user where id={$_post[' id ']}");  while ($result =mysql_fetch_array ($query)) {       echo $result [' name '];   }


This is a simple PHP query program. Now there is a problem that if $_post[' id ' is not found in the table, that is, mysql_query () cannot find the result.
The page is not showing results, but when using FF to catch the packet, it will respond with the following error:
Mysql_fetch_array (): supplied argument is not a valid MySQL result resource in./././line xx

I don't want him to give an error right now, I want to add a judgment in the program. How should I add?

I tried if ($query) if ($query! = False) if (mysql_num_rows ($query) <1) if (mysql_fetch_array ($query))
is useless.
mysql_query if the query is not found, will it return a pointer or false?
How should this judgment be written? Let's do a favor. Thank you ...


------Solution--------------------
You Var_dump (mysql_fetch_array ($query))) and look at what's going on, you don't know.
------Solution--------------------
Shouldn't be like you said.
When mysql_query () queries a matching result, a result set of type resource is returned
Returns a result set of type resource when there are no matching results
Returns False when the query is faulted
------Solution--------------------
So that's why you a.php.
You might as well put the code out, and mysql.php it.
------Solution--------------------
Not at all.
If there is an error, it is likely that your $_post[' ID ' does not fetch a value. Otherwise the error will not be reported.
------Solution--------------------
You do not use the method of post, directly with Get run mysql.php, the same ID to see what the result is
------Solution--------------------
For $query =mysql_query ("select * from user where id={$_post[' id ']}");
If $_post[' id '] does not exist, or is empty, the SQL instruction is
SELECT * from user where id=

If $_post[' ID ' is a non-digital quantity, he has said "deliberately mistaken a certain value of the query" then the SQL instruction is
SELECT * from user where id=xxx
XXX for string

Will inevitably produce a query error!


There will be text-type error messages in the event of an error, and FF will be able to see it by grasping the bag, and the FF should abandon
------Solution--------------------
Dude, you must be using Firefox! You clear the spring to see AH.
------Solution--------------------
Output SQL directly to see
  • 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.