0

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

i have an error being drawn with this code:

<?php
    include "config.inc.php";
        mysql_query($addClient) or die(mysql_error());
    $sth = mysql_query(
        sprintf(
            "SELECT c_id,p_id,p_title FROM projects WHERE c_id = %s",
            mysql_real_escape_string($_GET['id'])
        )
    );
    $projects = array();
    while($r = mysql_fetch_array($sth)) {
        $projects[] = array('id' => $r['p_id'], 'name' => $r['p_title']);
    }
    print json_encode($projects);
    exit;


?>

I get this error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/g/a/t/gatts316/html/clients/inc/get-projects.php on line 10

[]

Community
  • 1
  • 1

3 Answers3

1

Are you sure that is the right code? The error is referring to mysql_fetch_assoc() but there is no mysql_fetch_assoc() in the code you pasted. Where is $addClient defined? Perhaps something inside config.inc.php is wrong?

Paolo Bergantino
  • 480,997
  • 81
  • 517
  • 436
1

there is no mysql_fetch_assoc on above code, are you sure that was snippet code from get-projects.php?

Dels
  • 2,375
  • 9
  • 39
  • 59
0

I assume you changed mysql_fetch_assoc to mysql_fetch_array for testing... Anyway, the error should still persist.

You forgot to enclose the string %s in your query between '':

$sth = mysql_query(
    sprintf(
            "SELECT c_id,p_id,p_title FROM projects WHERE c_id = '%s'",
            mysql_real_escape_string($_GET['id'])
    )
);
Seb
  • 24,920
  • 5
  • 67
  • 85
  • That seemed to do the trick..thank you for the help! Appreciate it. Ryan –  Mar 17 '09 at 18:52