dongzongzhi6953 2015-09-02 20:46
浏览 18

PHP查询到CURL

i have a simple function, which should query the USGN number from the table and insert it into CURL request, but its giving white page...

For my bad luck i cannot provide error, its just blank page.

here is the script:

function getUSGNavatar($id) {
$usgn = mysql_query("SELECT * FROM cm_users WHERE USGN = '$usgn' AND ID = '$id'") or die(mysql_error());
return mysql_fetch_assoc($usgn);

// CURL 
$ch = curl_init('http://www.unrealsoftware.de/getuserdata.php?id='$usgn'&data=avatar');
curl_exec($ch);
if(!curl_errno($ch))
{
 $info = curl_getinfo($ch);
}
curl_close($ch);
// CLOSE function
}

Thanks for help

Something messed up with the query part i am sure, curl works okay, when ididn't used mysql worked fine.

I will rewrite Mysql into PDO, or MySQLI please dont mention it.

  • 写回答

2条回答 默认 最新

  • dongshan7708 2015-09-02 21:08
    关注

    You are returning i.e. return mysql_fetch_assoc($usgn); and you should not be as this will finish the function at that point.

    Oh and your string building in $ch = curl_init('http://www.unrealsoftware.de/getuserdata.php?id='$usgn'&data=avatar'); also had a problem.

    function getUSGNavatar($id) {
        $usgn = mysql_query("SELECT * 
                             FROM cm_users 
                             WHERE ID = '$id'");
        if ( ! $usgn ) {
            echo mysql_error();
        }
        $row = mysql_fetch_assoc($usgn);
    
        // CURL 
        $ch = curl_init('http://www.unrealsoftware.de/getuserdata.php?id=' . 
                        $row['USGN'] . '&data=avatar');
        curl_exec($ch);
        if(!curl_errno($ch)) {
            $info = curl_getinfo($ch);
        }
        curl_close($ch);
    
        // now you probably want to return something from the function
        return $info;
    }
    

    Oh and as per your request I will not nag you about the use of the deprecated mysql_ database extension, because we believe you that you will rewrite this code once its working, dont we?

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)