An error occurred while simulating the http post request in WinInet.

Source: Internet
Author: User
When an error occurs in a POST request simulating HTTP in WinInet, resumable trace execution is set in VS2012. it is found that the returned string requested for the PHP file is not correct, but the following error message is returned:

Invalid query:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''at line 1
Whole query:
Select id, name from index_activities where top = 0

This information is from PHP.
$result = mysql_query($query);

After the statement line, the "if" request is output only when the request is unsuccessful. it is obvious that the mysql request is unsuccessful and can be confirmed that the php file is successfully called.

However, when I call the same PHP file with the same parameters on the webpage (in the GET mode), the returned value is correct.

In my php file, it is used to retrieve passing parameters.
$top = $_REQUEST['top'];

Therefore, the POST and GET parameters can both be obtained.

I don't know where the problem may be? Does passing parameters with WinInet cause any exceptions in this request string?


Reply to discussion (solution)

Is the database connected correctly?

Is the database connected correctly?


The connection is correct. if the connection is incorrect, unable to connect to mysql will be returned, and the following request will not be executed or the MySQL request error message will not appear.

There is also an equivalent simulated HTTP request with parameters, and the returned result is correct:

Void CDllValidateDlg: ValidateAPerson (char * Name, char * Code) {CString post_data; post_data.Format ("userid = '% s' & name =' % s'", Code, name); // the request's additional parameter CString result; // The Returned result CString post_page = "test_id_validater/validateid. php "; // request phpPostHttpPage (result, post_page, post_data); AfxMessageBox (result );}

However, the HTTP request that I cannot understand now is different. I wrote all the parameters originally determined by the variables and still returned an error saying that the mysql request is incorrect:
void CDllValidateDlg::getActs(HTREEITEM root){CString post_data="top=0";//char top[10];//itoa(ActivitiesTree.GetItemData(root),top,10);//post_data.Format("top=%s",top);CString result;CString post_page = "test_id_validater/GetActivities.php";//AfxMessageBox("post_page:"+post_page+", "+"post_data:"+post_data);PostHttpPage(result, post_page, post_data);AfxMessageBox(result);    ……    ……

It seems to be a PHP issue. if you write it like below, it will return correct results:

 

The original code I wrote was:
 

Invalid query:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''at line 1
Whole query:
Select id, name from index_activities where top = 0
This information is clearly a database error!

If $ query = "select id, name from index_activities where top = 0"; yes
$ Query = "select id, name from index_activities where top = $ top"; no
This indicates that $ top has no value or is not a number.

$ Top = $ _ REQUEST ['top']; change to $ top = intval ($ _ REQUEST ['top']); try

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.