matt.sisto Posted May 2, 2009 Share Posted May 2, 2009 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> Link to comment https://forums.phpfreaks.com/topic/156594-solved-whats-wrong-with-my-sql-statement/ Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 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. Link to comment https://forums.phpfreaks.com/topic/156594-solved-whats-wrong-with-my-sql-statement/#findComment-824517 Share on other sites More sharing options...
matt.sisto Posted May 2, 2009 Author Share Posted May 2, 2009 Sorry, I wasn't sure because the sql relies upon the a php variable. Anyway when I echo out the value of $client_id, this is the result: Resource id #3. Link to comment https://forums.phpfreaks.com/topic/156594-solved-whats-wrong-with-my-sql-statement/#findComment-824520 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 No I meant the SQL. echo $sql; Link to comment https://forums.phpfreaks.com/topic/156594-solved-whats-wrong-with-my-sql-statement/#findComment-824521 Share on other sites More sharing options...
matt.sisto Posted May 2, 2009 Author Share Posted May 2, 2009 My mistake. Echoed $sql: SELECT client_id FROM client WHERE email_address= '[email protected]' Link to comment https://forums.phpfreaks.com/topic/156594-solved-whats-wrong-with-my-sql-statement/#findComment-824525 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.