Request query from database failed? A newbie, who made the first press release, encountered a problem on the news browsing interface. The following is a way to write PHPcodeinclude & quot; connect on the Internet. php & quot; $ id =$ _ GET [& quot; id & quot;]; $ query = & quot help: Why does the query request from the database fail?
Newbie: the first time I made a news release, I encountered a problem on the news browsing interface.
The following is a way of writing code on the Internet:
PHP code
include "connect.php"; $id=$_GET["id"];$query="SELECT * from news Where id=".$id;$result=mysql_query($query,$conn);$row=mysql_fetch_array($result);
The error is "Warning: mysql_fetch_array () expects parameter 1 to be resource ".
In fact, I don't quite understand the variable id in this writing method. Why can a newly defined variable be compared with the id in the database table?
How to change this error?
Thank you ~~
------ Solution --------------------
Add a line, echo mysql_error ();
It is estimated that the eight-to-one news table does not exist. how can this problem be solved?
------ Solution --------------------
1. as mentioned above, take a look at mysql_error ().
2. $ id variable is used to receive the value that the page passes through get, your webpage address should be: http://xxx.com? Id = 1. here, id value 1 is the value to be obtained. the news list is obtained by comparing this id value with the data table.
3. you can post connect. php for a moment.
------ Solution --------------------
You can adjust your SQL statement in the mysql editor. your code should be fine. I just don't know if your database connection code is faulty.
------ Solution --------------------
In fact, the landlord has already made it clear. Discussion
In fact, I don't quite understand the variable id in this writing method. Why can a newly defined variable be compared with the id in the database table?
How to change this error?
------ Solution --------------------
Discussion
1. as mentioned above, take a look at mysql_error ().
2. $ id variable is used to receive the value that the page passes through get, your webpage address should be: http://xxx.com? Id = 1. here, id value 1 is the value to be obtained. the news list is obtained by comparing this id value with the data table.
3. you can post connect. php for a moment.
------ Solution --------------------
Reminder... in the formal development work, if the correctness of the input parameters is not checked, the consequences will be devastating...
The original data obtained by $ _ GET and $ _ POST cannot be directly spliced in SQL... correctness check is required. this is common sense...
------ Solution --------------------
Discussion
Reminder... in the formal development work, if the correctness of the input parameters is not checked, the consequences will be devastating...
The original data obtained by $ _ GET and $ _ POST cannot be directly spliced in SQL... correctness check is required. this is common sense...