-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 ?

4
  • 3
    Obligatory 'do not use mysql_* functions' warning. They're now deprecated. Commented Mar 19, 2014 at 10:50
  • 1
    This means your query has failed, do a echo mysql_error(); or better more search before asking. Commented Mar 19, 2014 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. Commented Mar 19, 2014 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 () { .. } } Commented Mar 19, 2014 at 10:53

1 Answer 1

-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
}
?>
1
  • Wrong syntax of mysql_error(). The one parameter it accepts is the connection object. Refer here. Besides this is debugging method and not a solution. Commented Mar 19, 2014 at 11:04

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.