0

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.

6
  • stackoverflow.com/questions/845021/… Commented Sep 2, 2015 at 20:51
  • See link @CharlotteDunois posted, and turn on error reporting please. Commented Sep 2, 2015 at 20:52
  • Its turned on, but its defined in my functions.php, where there is thousand other function :/ Commented Sep 2, 2015 at 20:54
  • However i turned on, but still no errors just blank page Commented Sep 2, 2015 at 21:00
  • I made a new file with the function and now what i can see if undefine $usgn = mysql_query("SELECT * FROM cm_users WHERE USGN = '$usgn' AND ID = '$id'") or die(mysql_error()); return mysql_fetch_assoc($usgn); this part and remove id's and $usgn from curl thing its works fine, but i need to get that USGN number by mysql :( Commented Sep 2, 2015 at 21:05

2 Answers 2

2

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?

Sign up to request clarification or add additional context in comments.

17 Comments

exactly, now i dont get error, but i dont get my avatar so there is no url returned
When I run www.unrealsoftware.de/getuserdata.php?id=1&data=avatar I get u_ava/u1_4e989c1e.jpg returned. Are you sure you are using this returned information correctly. Then when I look at the url http://www.unrealsoftware.de/u_ava/u1_4e989c1e.jpg I see an image
unrealsoftware.de/getuserdata.php?id=6943&data=avatar i should get back this filename back and i can insert it into <img src="unrealsoftware.de/"functionname($id)"> But right now i got nothing :S
however i just tried to echo it, its still not display the filename
Try echo getUSGNavatar(6943); what does that return
|
1

you're getting the blank page because of this:

id='$usgn'&data

change this to:

id='.$usgn.'&data

you're missing the "."

1 Comment

That will fix the syntax error, but not make the function work correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.