本帖最后由 dimply 于 2014-06-09 14:02:10 编辑

解决方案 »

  1.   

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

  2.   

    另有一个同样的模拟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);
    }
    而我现在调试不明白的这个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);
        ……
        ……
      

  3.   

    感觉好像是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].",");
    }
    ?>
    原来我写的代码是:
    <?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].",");
    }
    ?>
      

  4.   

    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 无值或不是数字
      

  5.   

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