New users ask questions about why images cannot be displayed from databases on pages of mysql + php.

Source: Internet
Author: User
New users ask questions about how to display product names and corresponding images properly when calling images from databases on mysql + php pages.

1. index. php
... Omitted above

"Width =" 120 "height =" 135 "border =" 3 ">


Product Name:

<{$ Myrow [data]. tb_commodity_id}>


<{$ Myrow [data]. tb_commodity_name}>




2, head_picture.php
$ Query = "select * from tb_commodity where tb_commodity_id =". $ recid;
$ Result = mysql_query ($ query );
If (! $ Result) die ("error: mysql query ");
$ Num = mysql_num_rows ($ result );
If ($ num <1) die ("error: no this recorder ");
$ Data = mysql_result ($ result, 0, "tb_commodity_picture ");
Mysql_close ($ conn );
Echo $ data;
?>

3. the database table contains the tb_commodity_id, tb_commodity_name, and tb_commodity_picture fields.

On the index page, the product name can display 5 pieces of data in the database, including tb_commodity_id and tb_commodity_name. only images cannot be displayed normally, if you set $ query = "select * from tb_commodity where tb_commodity_id =" in head_picture.php ". $ recid; directly changed to: $ query = "select * from tb_commodity where tb_commodity_id = 1"; (or 2, 3, 4, 5, that is, the corresponding value of tb_commodity_id in the database) to display images normally, there are currently 5 data records in the database;
Change to: $ query = "select * from tb_commodity where tb_commodity_id =". $ myrow [data]. tb_commodity_id; display the tb_commodity_id = 5 image;
Click the image that cannot be displayed on the index page and open the image in the new tab. the URL in the address bar is: local name/head_picture.php? Recid = 5 (the corresponding recid is displayed in the image corresponding to the recid). the error: mysql query is displayed on the page.


Reply to discussion (solution)

Local name/head_picture.php? Recid = 5 (the corresponding recid is displayed in the image corresponding to the recid). the error: mysql query is displayed on the page.

The key point is to print the SQL statement display here.

Local name/head_picture.php? Recid = 5 (the corresponding recid is displayed in the image corresponding to the recid). the error: mysql query is displayed on the page.

The key point is to print the SQL statement display here.


The result is as follows: the. $ recid value is not taken to $ query = "select * from tb_commodity where tb_commodity_id =". $ recid.
Error: mysql query: select * from tb_commodity where tb_commodity_id =

$ Query = "select * from tb_commodity where tb_commodity_id =". $ _ GET ['recid'];

Find the crux of the problem.
$ Recid; change to $ _ GET ['recid'];
Or first extract ($ _ GET );

OK. Thank you @ xuzuning and @ anyilaoliu.

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.