An error occurred while querying requests from the database.

Source: Internet
Author: User
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...

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.