Jump to content

[SOLVED] Whats wrong with my SQL statement?


matt.sisto

Recommended Posts

For some reason my SQL statement is returning the wrong result and I don't understand why? When I echo out the SQL the result is: Resource id #3. Any help appreciated.

<?php
session_start();

  if (!isset($_SESSION['username']))
    {
   header("Location: login.php");
   exit();
  }
  
  require "dbconn2.php"; 
  
  $email_address = $_POST['email_address'];
  $unit = $_POST['unit'];
  $service = $_POST['service'];
  $quantity = $_POST['quantity'];
  $con_id1 = $_POST['con_id1'];
  $con_id2 = $_POST['con_id2'];
  $con_id3 = $_POST['con_id3'];
  $extra_info = $_POST['extra_info'];
  $start_time_hr = $_POST['start_time_hr'];
  $start_time_min = $_POST['start_time_min'];
  $time_sec = '00';
  $address_first_line = $_POST['address_first_line'];
  $post_code = $_POST['post_code'];
  $country = $_POST['country'];
  $month = $_POST["month"];
  $day = $_POST["day"];
  $year = $_POST["year"];

  $event_start = $year."-".$month."-".$day." ".$_POST["event_start"]; 
  $start_time = $start_time_hr.":".$start_time_min.":".$time_sec." ".$_POST["start_time"];

if ($unit == 'Day' && $quantity >= 1 && $quantity <= 7)
{
    $d = (int) $quantity;
    $event_end = strtotime("+$d Days", strtotime($event_start));
    $end_date = date('D j M Y', $event_end);
    $end_Time =$start_time;
} 
else if ($unit == 'Hour' && $quantity >= 1 && $quantity <= 7)
{
    $h = (int) $quantity;
    $end_time = strtotime("+$h Hours", strtotime($start_time));
    $end_Time = date('G:i:s', $end_time);
    $end_date = $event_start;
}
  $sql = "SELECT client_id FROM client WHERE email_address= '$email_address'";// This is returning the wrong result, Resource id #3
  $result1= mysql_query ($sql, $connection)
  or die ("Couldn't perform query $sql <br />".mysql_error());
  $client_id = $result1;

  $sql = "INSERT INTO calendar_events VALUES (0,'".$event_start."','".$end_date."','".$client_id."','".$service."','".$unit."','".$quantity."','".$start_time."','".$end_Time."','".$con_id1."','".$con_id2."','".$con_id3."','".$address_first_line."','".$post_code."','".$country."','".$extra_info."')";
  echo $sql;
  $result = mysql_query ($sql, $connection)
    or die ("Couldn't perform query $sql <br />".mysql_error());
  header("Location: bookingform.php");
  exit();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Book</title>
</head>
<body>
</body>
</html>

Hi,

I hope you know PHP Freaks does have a MySQL forum to post SQL problems - http://www.phpfreaks.com/forums/index.php/board,3.0.html

 

Please post in the correct forum next time.

 

echo out the query and paste it here please. My guess is that you need to escape the email address.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.