No error is returned for the PHP mysql insert request, but the database is not updated-php Tutorial

Source: Internet
Author: User
No error is returned for the PHP mysql insert request, but the following PHP code is not updated in the database:

$ Query = "insert into index_base (cardid, name, sex, nationality, birth, address, issued, expiration) values ($ cardid, $ name, $ gender, $ folk, $ birthday, $ addr, $ agency, $ expire) "; mysql_query ($ query); if ($ buy =" 1 ") {$ bid = mysql_insert_id (); echo ($ bid); $ time = date ("Y-m-d", time (); $ time. = ": 1"; $ query = "insert into index_b2a (bid, aid, 'limit', now) values ($ bid, $ aid, '$ time', 1) "; echo ($ query); $ result = mysql ($ query); echo (" result is ". $ result); if (mysql_affected_rows () = 1) die ("1"); else die ("0 ");}


According to the values returned by echo and die, the request $ query = "insert into index_b2a (bid, aid, 'limit', now) values ($ bid, $ aid, '$ time ', 1) "; it should be completely correct, $ result is 1, and affected rows is also 1.
However, in the database, I cannot find the inserted path.

I added an echo ($ query). The printed request is insert into index_b2a (bid, aid, 'limit', now) values (102631, '89 ', '2017-06-13', 1). enter mysql directly. of course, the execution is correct. after refreshing the database, you can immediately see the inserted entries.

Because limit is a keyword, I have added ''as a quotation mark.
To ensure that no error is caused, the quotation marks outside 89 are also removed. The value: 1 is also changed, and the colon and number 1 are removed.
Then execute:
It still takes effect in mysql, but does not take effect in php, but the returned values indicate that the execution is successful.

I don't know where the problem is?


Reply to discussion (solution)

$ Result = mysql ($ query); is mysql () your custom function? Or by mistake?

Echo mysql_error (); to see if there are any errors.

Is the wrong database entered?

$ Result = mysql ($ query); what is this?

I also encountered the same problem. insert and update cannot be completed.

I also encountered the same problem. insert and update cannot be completed.



I checked and found nothing. I finally got a MySql API document, found the code segment, and changed the corresponding field. It should be a problem with statement characters (I don't know either ...).

I have attached my insert-able code, and you have tried to modify the content, hoping to solve your problem:
    $sql="insert into resell_info (id, user, datetime, content) values (null,'12345',null,'12345')";    mysql_query($sql);

It is best to add the second parameter of the mysql_query () function.

Paste the program running result

Learning, learning, learning

Mysql_query (query, connection );

You must have not connected to the database.


If the test succeeds in mysql, the statement is correct. However, the test in mysql is actually performed in the connected database status.

But on the php page, the first thing you need to do is to first connect to the database and add the connection parameter.

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.