WinInet analog HTTP POST request error

Source: Internet
Author: User
Set the breakpoint trace execution inside the VS2012, and find that the PHP file is not getting the correct return string, but the following error message:

Invalid query:
You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near "at line 1
Whole query:
Select Id,name from Index_activities where top=0

This is the message I have in PHP
$result = mysql_query ($query);

After the statement line, the "if" request is not successful, obviously the MySQL request is unsuccessful, and you can determine that the PHP file was successfully invoked.

But when I call the same PHP file with the same parameters in the Web page (get mode), the return value is correct.

My php file is used to get the parameters.
$top = $_request[' top '];

So the post and get parameters should all be equally available.

Don't know where it might have gone wrong? Do you have any exceptions to this request string by WinInet?


Reply to discussion (solution)

is the database connection correct?

is the database connection correct?


The connection is correct, the incorrect return unable to connect to MySQL, will not execute to the following request, there will be no MySQL request error message.

There is also the same analog HTTP request, with parameters that return is correct:

void Cdllvalidatedlg::validateaperson (char* Name, char* Code) {CString post_data;post_data. Format ("userid= '%s ' &name= '%s '", code,name); Additional parameters of the request CString result; The returned result CString post_page = "test_id_validater/validateid.php"; Phpposthttppage of the request (Result,post_page,post_data); AfxMessageBox (result);}

And I am now debugging do not understand this HTTP request, exactly where it is not the same, I left the parameters determined by the variables are dead, still return to say 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 feels like a php-side problem and returns to the correct one as follows:

 
  

The original code I wrote was:
 
  

Invalid query:
You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near "at line 1
Whole query:
Select Id,name from Index_activities where top=0
This information is clearly the fault of the database report!

If $query = "Select Id,name from Index_activities where top=0"; OK
and $query = "Select Id,name from index_activities where top= $top"; No
This means $top no value or no number

$top = $_request[' top ']; Change to $top = Intval ($_request[' top '); Give it a 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.