An error occurred while reading data from the MySQL table.

Source: Internet
Author: User
An error occurred while reading data from the MySQL table. mysql select php

Below is a piece of code that works normally
/* Inject basic information. A_ I automatically generates meta_id */$ query1 = "INSERT INTO libr_metacode (meta_isbn, meta_cip) VALUES ('$ isbn', '$ cip ')"; $ result1 = mysqli_query ($ dbc, $ query1) or die ('unable to write the basic encoding, error message :'. mysqli_error ($ dbc);/* obtain meta_id for subsequent writing */$ query = "SELECT * FROM libr_metacode WHERE meta_isbn = '$ isbn '"; $ result = mysqli_query ($ dbc, $ query); $ row = mysqli_fetch_array ($ result); $ ida = $ row ['meta _ id']; echo 'obtain the metadata of the library system in this book '. $ ida.'
';/* Title */$ query2 = "insert into libr_title (meta_id, title, subtitle, series) VALUES (' $ ida ',' $ title', '$ title ', '$ series') "; $ result2 = mysqli_query ($ dbc, $ query2) or die ('title information cannot be written, error :'. mysqli_error ($ dbc ));


What we do is:

1. Insert the ISBN number (International Standard Book Number) and CIP number obtained in the form into the meta_code table.
2. use the unique ISBN number to query the system metadata obtained by books in the meta_code table.
3. Insert data into multiple tables using system metadata

Because ISBN has 13 bits and is not suitable for primary keys ?), So this is done, but when reading other data, almost identical query code will go wrong.

/* Get meta_id for subsequent writing */$ query = "SELECT * FROM '$ ui_ B' WHERE '$ ui_c' = '$ ui_a'"; $ result = mysqli_query ($ dbc, $ query); $ row = mysqli_fetch_array ($ result); $ ida = $ row ['meta _ id'];


Error: mysqli_fetch_array () expects parameter 1 to be mysqli_result, boolean given.

Although we know that $ result should return a resource id, we can use fetch_array () in the first code. why must fetch_array () be a logical value in the second code?

Also, how can I "echo" the value of $ result?


Reply to discussion (solution)

Supplement: The system metadata is automatically incremented by A_ I. $ ui_a inputs the field value, $ ui_ B inputs the table name, and $ ui_c inputs the column name.

If $ ui_ B is the table name and $ ui_c is the field name
Writing
$ Query = "SELECT * FROM $ ui_ B WHERE $ ui_c = '$ ui_a '";

If $ ui_ B is the table name and $ ui_c is the field name
Writing
$ Query = "SELECT * FROM $ ui_ B WHERE $ ui_c = '$ ui_a '";
I'm going ...... That's right ...... Thank you!

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.