3 Replies - 7847 Views - Last Post: 30 November 2010 - 07:45 AM Rate Topic: -----

#1 marqueezTi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-November 10

You have an error in your SQL syntax; check the manual that correspond

Posted 30 November 2010 - 07:01 AM

i received this error message -->
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\script.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



<?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;
[i][b]Line 24-->	[/b][/i]if($row = mysql_fetch_array($resultz)){
	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'>";
	}

?>






Is This A Good Question/Topic? 0
  • +

Replies To: You have an error in your SQL syntax; check the manual that correspond

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6033
  • View blog
  • Posts: 23,415
  • Joined: 23-August 08

Re: You have an error in your SQL syntax; check the manual that correspond

Posted 30 November 2010 - 07:15 AM

Do this:
$sql = "select * FROM booking WHERE date = '$date' AND time = '$time' AND courts = '$courts' ";
$resultz = mysql_query($sql) or die("Query $sql failed: " . mysql_error());


And come back with the error message.

EDIT: Also, you're ripe for SQL Injection. Read this.

This post has been edited by JackOfAllTrades: 30 November 2010 - 07:17 AM

Was This Post Helpful? 1
  • +
  • -

#3 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2889
  • View blog
  • Posts: 10,002
  • Joined: 08-August 08

Re: You have an error in your SQL syntax; check the manual that correspond

Posted 30 November 2010 - 07:15 AM

You need to fetch the array. See this tutorial:
http://www.dreaminco...beginners-look/
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6033
  • View blog
  • Posts: 23,415
  • Joined: 23-August 08

Re: You have an error in your SQL syntax; check the manual that correspond

Posted 30 November 2010 - 07:45 AM

I have added this to the PHP FAQs as "Problem #3".
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1