I'm sorry to disturb everyone on Sunday, but I am in a hurry ...... PHPcode $ querymysql_query (& quot; select * fromuserwhereid]} & quot;); while ($ resultmysql_fetch_array ($ query) {ech is sorry to disturb you on Sunday, but it's really anxious ...... 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. One problem is that if $ _ POST ['id'] cannot be found in the table, that is, mysql_query () cannot find the result.
No results are displayed on the page, but when you use FF to capture packets, the following error will be returned:
Mysql_fetch_array (): supplied argument is not a valid MySQL result resource in./line xx
I don't want him to report an error, but I want to add a judgment in the program. How should I add it?
I tried if ($ query) if ($ query! = False) if (mysql_num_rows ($ query) <1) if (mysql_fetch_array ($ query ))
It is useless.
If mysql_query cannot be queried, will the pointer or false be returned?
How should I write this judgment? Please help me. Thank you ......
------ Solution --------------------
You first var_dump (mysql_fetch_array ($ query) to see what is returned, you don't know
------ Solution --------------------
It shouldn't be like what you said
When mysql_query () queries matching results, a resource-type result set is returned.
If no matching result exists, the returned result set is of the resource type.
Returns false when a query error occurs.
------ Solution --------------------
That's why you are a. php.
Paste the code and paste mysql. php.
------ Solution --------------------
No.
If an error occurs, most of them are because your $ _ POST ['id'] does not get the value. Otherwise, no error will be reported ..
------ Solution --------------------
You don't need to use the post method to directly run mysql. php with get. use 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 command is
Select * from user where id =
If $ _ POST ['id'] is not a numeric value, the SQL command is
Select * from user where id = xxx
Xxx is a string
A query error is inevitable!
If an error occurs, there will be a text-type error message. ff can only be seen through packet capture. this ff should be discarded.
------ Solution --------------------
You must use Firefox! Let's take a look at it later.
------ Solution --------------------
Directly output SQL