Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial WinInet模拟HTTP的POST请求出错

WinInet模拟HTTP的POST请求出错

Jun 23, 2016 pm 01:55 PM
http post Error simulation ask

在VS2012里面设置断点跟踪执行,发现请求该php文件获取的不是正确的返回字串,而是如下出错信息:

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

这段信息是我在PHP的

$result = mysql_query($query);
Copy after login

语句行后面,“if”请求不成功才输出的,显然是mysql请求没成功,且可以确定,调用该PHP文件是成功的。

但是当我在网页中用同样的参数调用同一个PHP文件时(GET方式),返回值则是正确的。

我php文件中获取传参是用的
$top = $_REQUEST['top'];
Copy after login

所以POST和GET参数应该都可以同样获取的。

不知道可能是哪里出了问题?用WinInet传参会造成这个请求字串有什么异常吗?


回复讨论(解决方案)

数据库连接正确吗?

数据库连接正确吗?


连接正确啊,不正确就返回unable to connect to mysql了,就不会执行到下面的请求,也不会出现MySQL的请求出错信息了。

另有一个同样的模拟HTTP请求,也有参数,返回就是正确的:

void CDllValidateDlg::ValidateAPerson(char* Name, char* Code){	CString post_data;	post_data.Format("userid='%s'&name='%s'",Code,Name); //请求的附加参数	CString result; //返回的结果	CString post_page = "test_id_validater/validateid.php"; //请求的php	PostHttpPage(result,post_page,post_data);	AfxMessageBox(result);}
Copy after login

而我现在调试不明白的这个HTTP请求,到底哪里不一样,我把原本由变量决定的参数都写死了,仍然返回说mysql请求不正确:
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);    ……    ……
Copy after login

感觉好像是PHP端的问题,像下面这么写就返回正确了:

<?phprequire "use_daoru.php";$top = $_REQUEST['top'];$query = "select id,name from index_activities where top=0";$result = mysql_query($query);//if(!$result){//$message = 'Invalid query: '.mysql_error()."\n";//$message.= 'Whole query: '.$query;//die($message);//}$num = mysql_num_rows($result);for($i=0;$i<$num;$i++){	$row = mysql_fetch_row($result);	echo($row[0].":".$row[1].",");}?>
Copy after login

原来我写的代码是:
<?phprequire "use_daoru.php";$top = $_REQUEST['top'];$query = "select id,name from index_activities where top=$top";$result = mysql_query($query);//if(!$result){//$message = 'Invalid query: '.mysql_error()."\n";//$message.= 'Whole query: '.$query;//die($message);//}$num = mysql_num_rows($result);for($i=0;$i<$num;$i++){	$row = mysql_fetch_row($result);	echo($row[0].":".$row[1].",");}?>
Copy after login

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
这个信息分明是数据库报的错!

如果 $query = "select id,name from index_activities where top=0"; 可以
而 $query = "select id,name from index_activities where top=$top"; 不可以
这就表示 $top 无值或不是数字

$top = $_REQUEST['top']; 改为  $top = intval($_REQUEST['top']); 试试

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does http status code 520 mean? What does http status code 520 mean? Oct 13, 2023 pm 03:11 PM

What does http status code 520 mean?

Understand common application scenarios of web page redirection and understand the HTTP 301 status code Understand common application scenarios of web page redirection and understand the HTTP 301 status code Feb 18, 2024 pm 08:41 PM

Understand common application scenarios of web page redirection and understand the HTTP 301 status code

http request 415 error solution http request 415 error solution Nov 14, 2023 am 10:49 AM

http request 415 error solution

How to implement HTTP streaming using C++? How to implement HTTP streaming using C++? May 31, 2024 am 11:06 AM

How to implement HTTP streaming using C++?

HTTP 200 OK: Understand the meaning and purpose of a successful response HTTP 200 OK: Understand the meaning and purpose of a successful response Dec 26, 2023 am 10:25 AM

HTTP 200 OK: Understand the meaning and purpose of a successful response

AI simulator takes the new SOTA in physics simulation! AI simulator takes the new SOTA in physics simulation! Feb 19, 2024 pm 06:50 PM

AI simulator takes the new SOTA in physics simulation!

PHP code example: How to use POST to pass parameters and implement page jumps PHP code example: How to use POST to pass parameters and implement page jumps Mar 07, 2024 pm 01:45 PM

PHP code example: How to use POST to pass parameters and implement page jumps

How to implement PHP to jump to the page and carry POST data How to implement PHP to jump to the page and carry POST data Mar 22, 2024 am 10:42 AM

How to implement PHP to jump to the page and carry POST data

See all articles