I keep on getting this error = Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in this code :`

        //this will trigger automatically when they change the first select box
        $('#dateFilter').on('change', function(event){
        if($(this).val() == 'dateFilter'){
            var values = $(this).serialize();
                url: "AdvanceOption.php",
                type: "post",
                data: values,
                success: function(data){
                $("#ajax_reply_div").empty().append('something went wrong');

    <div id='center'>
        <?php include  "header.php"; // display menu options ?>

                <form id = "project_form" method="post">
                    <div id="searchPanel">
                            echo "Choose a date"; 
                            $something_date = $sample->retrieveFilterDate(); 
                            $data_date = array();
                            echo  "<select id='dateFilter' class='dateFilter' name='dateFilter'>";
                            while($row_date = mysql_fetch_assoc($something_date)){
                              array_push($data_date, $row_date);
                              echo  "<option value='".$row_date['date']."' >".$row_date['date']." </option>";
                            echo "</select>";

                            echo "\tChoose a place";
                            $something_place = $rm->retrieveFilterplace(); 
                            $data_place = array();
                            echo  "<select id='placeFilter' class='placeFilter' name='placeFilter'>";
                            while($row_place = mysql_fetch_assoc($something_place)){
                              array_push($data_place, $row_place);
                              echo  "<option value='".$row_place['placeNumber']."' >".$row_place['placeNumber']." </option>";
                            echo "</select>";

                        if((isset($_POST['dateFilter'])) && (isset($_POST['placeFilter']))){
                            $result = mysql_query("SELECT nameNumber,time,user_id * FROM table_something WHERE '".$_POST['dateFilter']."' AND '".$_POST['placeFilter']."'   ");
                            echo "<option value=''>Select Your Album</option>";
                            while($row = mysql_fetch_array($result)){
                                echo "<option value='" . $row['nameNumber'] . "'>" . $row['time'] . "</option>";


                          <div id="ajax_reply_div">
                         <input type="submit" value="Submit">

The error is in this line while($row = mysql_fetch_array($result)){. The process is that the user will select from the two select option then click the submit button then there will be the output of rows related to the selection of the user from the two select option. Any help will really be appreciated.



You are getting this error because $result is a boolean. You can read up on the documentation for how that function works here on the PHP documentation site.

$result = mysql_query("SELECT nameNumber,time,user_id * FROM table_something WHERE '".$_POST['dateFilter']."' AND '".$_POST['placeFilter']."'   ");

You are likely getting this because your SELECT query has been formed incorrectly and is instead generating an error.

Not only do you need to remove the * as shown below, but your WHERE clause is likely invalid as you aren't actually comparing any values. Read more about the WHERE clause here

$result = mysql_query("SELECT nameNumber,time,user_id FROM table_something WHERE '".$_POST['dateFilter']."' AND '".$_POST['placeFilter']."'   ");

You might also want to look into PDO or MySQLi extensions for manipulating your database as the mysql_* functions are now deprecated and will be removed (see the big red box on the php manual page?). Also look into how to prevent SQL Injection to make your code safer

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top