The SQL statement on the php page is successfully executed and the database is not updated.

Source: Internet
Author: User
The SQL statement on the php page is successfully executed. if the database is not updated, I create a page about voting. the database connection is successful. The following is the method for executing the SQL statement. no error is returned for the query. 2 is returned, however, the database data is not updated.
However, if the SQL statement is executed successfully in phpmyadmin, the data can also be updated.
$ SQL = "update vote set num = num + 1 where name = 'Bush '";

Public function execute_dml ($ SQL) {$ B = mysql_query ($ SQL, $ this-> conn) or die ("execution failed! ". Mysql_error (); if (! $ B) {return 0; // execution failed} else {if (mysql_affected_rows ($ this-> conn)> 0) {return 1; // execute OK} else {return 2; // it indicates that no row is affected }}}


I think the code should be okay. it should be another problem.


Reply to discussion (solution)

If not, it may be encoding. For example, 'Bush 'is the UTF-8 code on the page and the database is GBK.
We recommend that you use primary key query to ensure uniqueness.

Encoding problem. what is the encoding of your table? have you executed the set names utf8 statement.

If not, it may be encoding. For example, 'Bush 'is the UTF-8 code on the page and the database is GBK.
We recommend that you use primary key query to ensure uniqueness.


The primary key query is successful. Thank you. Ah, I don't know much about mysql databases.

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.