-4

Here is the code of : select_class.php

 <?php 

    $get_userclass_query="select courseandbatch from studentdetails group by courseandbatch          ";
    $get_userclass_result=mysql_query($get_userclass_query);
    while($get_userclass_row=mysql_fetch_array($get_userclass_result))
   {?>
    <option value="<?php echo $get_userclass_row['courseandbatch']; ?>"><?php echo     $get_userclass_row['courseandbatch']; ?></option>
    <?php echo $get_userclass_row['courseandbatch']; ?><?php
}
?>

code:sis.php
 Batch:<input type="text"  /><select name="search"  style="width:100px; height:20px;" >
    <?php
    include '../select_class.php';
    ?>
     </select> 

When I execute this page, I have the following error:

mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\apnacar\select_class.php on line 5

How can I fix this ?

  • 3
    Obligatory 'do not use `mysql_*` functions' warning. They're now deprecated. – BenM Mar 19 '14 at 10:50
  • 1
    This means your query has failed, do a `echo mysql_error();` or better more search before asking. – AyB Mar 19 '14 at 10:51
  • 1
    The `mysql_query()` has failed but you have no error processing code in there to check it. When `mysql_query()` fails it returns `FALSE` and not a result handle, and you get this error. – RiggsFolly Mar 19 '14 at 10:52
  • 1
    Your query has failed. You can add fail safe to your code like this: `if ($get_userclass_result && mysql_num_rows($get_userclass_result) > 0) { while () { .. } }` – Latheesan Mar 19 '14 at 10:53

1 Answers1

-1
 <?php 

    $get_userclass_query="select courseandbatch from studentdetails group by courseandbatch          ";
    $get_userclass_result=mysql_query($get_userclass_query);
    if($get_userclass_result === FALSE) {
     die(mysql_error()); 
   }
    while($get_userclass_row=mysql_fetch_array($get_userclass_result))
   {?>
    <option value="<?php echo $get_userclass_row['courseandbatch']; ?>"><?php          echo $get_userclass_row['courseandbatch']; ?></option>
    <?php echo $get_userclass_row['courseandbatch']; ?><?php
}
?>
bikalsh
  • 29
  • 5
  • Wrong syntax of mysql_error(). The one parameter it accepts is the connection object. Refer [here](http://www.php.net/mysql_error). Besides this is debugging method and not a solution. – AyB Mar 19 '14 at 11:04