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.

Marcell
  • 500
  • 1
  • 4
  • 19
  • http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php – Charlotte Dunois Sep 02 '15 at 20:51
  • See link @CharlotteDunois posted, and turn on error reporting please. – kittykittybangbang Sep 02 '15 at 20:52
  • Its turned on, but its defined in my functions.php, where there is thousand other function :/ – Marcell Sep 02 '15 at 20:54
  • However i turned on, but still no errors just blank page – Marcell Sep 02 '15 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 :( – Marcell Sep 02 '15 at 21:05
  • You should be getting a syntax error for the `$ch =` line, because you're missing the `.` to concatenate the strings with the variable. – Barmar Sep 02 '15 at 21:09

2 Answers2

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?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • exactly, now i dont get error, but i dont get my avatar so there is no url returned – Marcell Sep 02 '15 at 21:22
  • 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 – RiggsFolly Sep 02 '15 at 21:26
  • http://www.unrealsoftware.de/getuserdata.php?id=6943&data=avatar i should get back this filename back and i can insert it into But right now i got nothing :S – Marcell Sep 02 '15 at 21:27
  • however i just tried to echo it, its still not display the filename – Marcell Sep 02 '15 at 21:29
  • Try `echo getUSGNavatar(6943);` what does that return – RiggsFolly Sep 02 '15 at 21:31
  • Returns Array thats all – Marcell Sep 02 '15 at 21:33
  • So do `print_r(getUSGNavatar(6943));` and see what the function is returning and amend what it returns accordingly so your ` – RiggsFolly Sep 02 '15 at 21:33
  • This is rapidly getting into the area of Question.Scope Creep. I think you need to finish with this question as it is answered and ask a new question. Oh and delete that answer, thats not how you add info to a question. In future edit your question. – RiggsFolly Sep 02 '15 at 21:43
  • Ask a new question? Sorry but i dont know what could i say for the "problem". – Marcell Sep 02 '15 at 21:46
  • I get this data and I dont know what to do with it – RiggsFolly Sep 02 '15 at 21:46
  • Maybe you should also check what is returned from the query as that data shows nothing in the `id=` field on the url. I dont know what the columns are actually called on your database so `$row['USGN']` may be misspelled – RiggsFolly Sep 02 '15 at 21:49
  • Actually I just spotted a **possible** mistake in your QUERY. I removed `USGN = '$usgn'` from your WHERE as I see no `$usgn` for you to use in this scope – RiggsFolly Sep 02 '15 at 21:51
  • http://prntscr.com/8bxf01 its looks like this, however i deleted USGN = '$usgn' but still not work – Marcell Sep 02 '15 at 21:54
  • You need to do some research on the extra CURL parameters you need to get curl to run properly – RiggsFolly Sep 02 '15 at 22:07
  • Problem with no CURL i fugred out Now i trying to run function getUSGNavatar($id) { $usgn = mysql_query("SELECT * FROM cm_users WHERE ID = '$id'") or die(mysql_error()); $row = mysql_fetch_assoc($usgn); echo "sad " . $row['USGN']. " when"; } and just return "sad when" without ID, so problem with query – Marcell Sep 02 '15 at 22:08
  • $usgn = mysql_query("SELECT * FROM cm_servers WHERE ID = '$id'") or die(mysql_error()); $row = mysql_fetch_assoc($usgn); echo mysql_error(); like this? i did but no errors – Marcell Sep 02 '15 at 22:15
  • Fixed the issue by my self! However you answered the most helpful answer so take my like! – Marcell Sep 02 '15 at 22:28
1

you're getting the blank page because of this:

id='$usgn'&data

change this to:

id='.$usgn.'&data

you're missing the "."

Barmar
  • 741,623
  • 53
  • 500
  • 612
dFine
  • 21
  • 3