No error is returned for the mysql insert request in PHP, but the database is not updated.

Source: Internet
Author: User
No error is returned for the mysql insertion request of PHP, but the database has not updated this post. the following PHP code $ query & nbsp is edited by dimply at 2014-06-1321: 46: 24; & nbsp; insert & nbsp; into & nbsp; index_base & nbsp; (cardid, & nbsp; name, & PHP's mysql insertion request returns no error, but the database is not updated

This post was last edited by dimply at 21:46:24

The following PHP code is provided:

$ 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?
------ Solution --------------------
$ Result = mysql ($ query); is mysql () your custom function? Or by mistake?

Echo mysql_error (); to see if there are any errors.
------ Solution --------------------
$ Result = mysql ($ query); what is this?

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.