-4

Why do I get an error in my program?

The code is:

$q = mysql_query("SELECT * FROM rpard WHERE grup='12' ");
$r = mysql_fetch_array($q);
$nil = ($r['nilai']);
{
    while($data = mysql_fetch_array($q)){
        echo "<option value='".trim($data['nilai'])."'>".$data['nilai']."</option>";
}
echo "$q";
}
?>

Error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\newoppel\mod\inventaris\ruang-new.php on line 6

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\newoppel\mod\inventaris\ruang-new.php on line 9

Community
  • 1
  • 1
Widu
  • 11
  • 1
  • 1
  • 3
  • check your query error mysql_error after query execution – Sundar Dec 10 '13 at 07:18
  • 1
    Do not use `mysql_` API it has been deprecated by PHP http://php.net/manual/en/book.mysql.php – Noor Dec 10 '13 at 07:19
  • 1
    There are dozens of questions with the same title in the **Related** list. Didn't any of them point you in the direction to solve this yourself? – Barmar Dec 10 '13 at 07:21
  • Please check this reference : http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12770072#12770072 – Sadikhasan Dec 10 '13 at 07:31

2 Answers2

0

Change:

while($data = mysql_fetch_array($q)){

to:

while($data = mysql_fetch_array($r)){

Also change:

$q = mysql_query("SELECT * FROM rpard WHERE grup='12' ");

to:

$q = mysql_query("SELECT * FROM rpard WHERE grup='12' ") or die(mysql_error());

because it looks like that query is failing, and you need to see the error message.

Barmar
  • 669,327
  • 51
  • 454
  • 560
  • and then i also get error more "Warning: mysql_fetch_array() expects parameter 1 to be resource, array given in D:\xampp\htdocs\newoppel\mod\inventaris\ruang-new.php on line 10 Resource id #5" @Barmar – Widu Dec 10 '13 at 07:52
  • Can you update your question to mark the line numbers with the errors? – Barmar Dec 10 '13 at 07:57
  • Just make sure you put `or die(mysql_error())` after every call to `mysql_query()`. – Barmar Dec 10 '13 at 07:57
0

Look your query is failing so add

or die(mysql_error() 

at the end of the query