Jump to content

Recommended Posts

Hi All

Can someone please tell me what am I doing wrong in this query??? Its inserting everthing even those date that are already there. So basically its this line that's not working.

if (($result) == ($_POST['s_time'])) {

why???

Many thanks

Zed

function insert(){
$b_id = $_POST['b_id'];
$dateTime = $_POST['dateTime'];
$user_id = $_POST['user_id'];
$s_time = $_POST['s_time'];
$e_time = $_POST['e_time'];
$request_date = $_POST['request_date'];

     $query = "SELECT s_time,request_date FROM booking WHERE request_date = '$request_date'";
echo "$query";
     $result = mysql_query($query)or die(mysql_error());

if (($result) == ($_POST['s_time'])) {
	error_message("Sorry, this hour/s is already booked please choose another !");   
}else{
$query = "INSERT INTO booking  VALUES
(NULL,'$dateTime','$user_id','$s_time','$e_time','$request_date')";
	if (@mysql_query($query)) {
		comfirmed_booking();
		} else {
		echo '<p>Error adding submitted Information: ' .
		mysql_error() . '</p>';
	}//end of else
}//end of if
}//end of insert

Link to comment
https://forums.phpfreaks.com/topic/171615-query-not-working/
Share on other sites

Hi All

Can someone please tell me what am I doing wrong in this query??? Its inserting everthing even those date that are already there. So basically its this line that's not working.

if (($result) == ($_POST['s_time'])) {

why???

Many thanks

Zed

function insert(){
$b_id = $_POST['b_id'];
$dateTime = $_POST['dateTime'];
$user_id = $_POST['user_id'];
$s_time = $_POST['s_time'];
$e_time = $_POST['e_time'];
$request_date = $_POST['request_date'];

     $query = "SELECT s_time,request_date FROM booking WHERE request_date = '$request_date'";
echo "$query";
     $result = mysql_query($query)or die(mysql_error());

if (($result) == ($_POST['s_time'])) {
	error_message("Sorry, this hour/s is already booked please choose another !");   
}else{
$query = "INSERT INTO booking  VALUES
(NULL,'$dateTime','$user_id','$s_time','$e_time','$request_date')";
	if (@mysql_query($query)) {
		comfirmed_booking();
		} else {
		echo '<p>Error adding submitted Information: ' .
		mysql_error() . '</p>';
	}//end of else
}//end of if
}//end of insert

 

i'm not great with php but I think you need to get your results into a variable from your result set

 

like such: $row = mysql_fetch_array($result);

 

if ( $row['s_time'] == $_POST['s_time'] )

 

not sure that helps but i tried lol

Link to comment
https://forums.phpfreaks.com/topic/171615-query-not-working/#findComment-904960
Share on other sites

<?php

$query = "SELECT s_time,request_date FROM booking WHERE request_date = '$request_date'";

$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array($result); //you need to pull the results out so you can compare it to the request

if ( $row['s_time'] == $_POST['s_time'] )
{
error_message("Sorry, this hour/s is already booked please choose another !");   
}

else
{
$query = "INSERT INTO booking  VALUES
(NULL,'$dateTime','$user_id','$s_time','$e_time','$request_date')";

?>

Link to comment
https://forums.phpfreaks.com/topic/171615-query-not-working/#findComment-904967
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.