mysql_fetch_array() expects parameter 1 to be resource, ...error in your SQL syntax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mocha
    New Member
    • Nov 2010
    • 2

    mysql_fetch_array() expects parameter 1 to be resource, ...error in your SQL syntax

    I have this error message --> Warning: mysql_fetch_arr ay() expects parameter 1 to be resource, boolean given in C:\wamp\www\scr ipt.php on line 24

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'date']; ?>','3:00am')' at line 1

    The one that i bold and underline is Line 24

    Code:
    <?php
    session_start();
    	
    $hostname = "localhost";
    $username = "root";
    $password = "";
    $dbname = "futsal";
    $tblname = "booking";
    
    $connection = mysql_connect($hostname, $username, $password) or die(mysql_error());
    $db = mysql_select_db($dbname, $connection) or die (mysql_error());
    
    $username = $_SESSION['username'];
    $courts = $_POST['courts'];
    $date = $_POST['date'];
    $time = $_POST['time'];
    
    	$result_user_id = mysql_query("select user_id FROM user WHERE username = '$username'");
    	if($row = mysql_fetch_array($result_user_id)){
    	$user_id = $row['user_id'];
    	}
    	
    	$resultz = mysql_query("select * FROM booking WHERE date = '$date' AND time = '$time' AND courts = '$courts' ");echo $resultz;
    [B][I]line 24->	[/I][/B]	[I][U][B]if($row = mysql_fetch_array($resultz)){[/B][/U][/I]
    	echo "<table width='100%'><td height='50' align='center' bgcolor='#85A157'><font size='4'><strong>The court are not available</strong></font></td></table>";
    	echo "<meta http-equiv='refresh' content='1;url=booking.php'>";
    	}
    
    	else
    	{
    	$sql = "INSERT INTO booking(user_id,username,courts,date,time) VALUE ('$user_id','$username','$courts','$date','$time')";
    $result = mysql_query($sql) or die (mysql_error());
    	
    	$_SESSION['courts'] = $courts;
    	$_SESSION['date'] = $date;
    	$_SESSION['time'] = $time;
    	
    
    
    	//echo "<meta http-equiv='refresh' content='10;url=booking_success.php'>"
    	echo "<table width='100%'><td height='50' align='center' bgcolor='#85A157'><font size='4'><strong>PROCESS BOOKING</strong></font></td></table>";
    	echo "<table width='1000'><td align='center'><img src='image futsal/loading3.gif'></td></table>";
    	echo "<meta http-equiv='refresh' content='1;url=booking_success.php'>";
    	}
    
    ?>
    Last edited by Niheel; Nov 30 '10, 06:42 PM.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the error message says it all. your SQL query fails, therefore mysql_query() returns false (a boolean) and that is not the expected parameter type (resource) for mysql_fetch_arr ay().

    Comment

    • mocha
      New Member
      • Nov 2010
      • 2

      #3
      does this mean phpMyAdmin has false sql query??

      Because my friend can run it without problem at all.I wonder why..

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        not phpMyAdmin has a false query, you have. print out the SQL string before submitting it and check the syntax.

        Comment

        Working...