matt.sisto Posted May 2, 2009 Share Posted May 2, 2009 Hi all, I am stuggling to define the value of a variable by using a form input to select a value form a table, to then INSERT into another table. Any help appreciated <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $email_address = mysql_real_escape_string($_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 = mysql_real_escape_string($_POST['address_first_line']); $post_code = $_POST['post_code']; $country = mysql_real_escape_string($_POST['country']); $month = mysql_real_escape_string($_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'"; $result1= mysql_query($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); while ($row = mysql_fetch_assoc($result1)) { $client_id = $row; } $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> Thanks and regs. Link to comment https://forums.phpfreaks.com/topic/156600-problem-using-sql-select-statement-to-define-a-variable-value/ Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 You have NO form fields. Link to comment https://forums.phpfreaks.com/topic/156600-problem-using-sql-select-statement-to-define-a-variable-value/#findComment-824556 Share on other sites More sharing options...
matt.sisto Posted May 3, 2009 Author Share Posted May 3, 2009 My form is on a previous page which posts the values to the script. Link to comment https://forums.phpfreaks.com/topic/156600-problem-using-sql-select-statement-to-define-a-variable-value/#findComment-824812 Share on other sites More sharing options...
fenway Posted May 4, 2009 Share Posted May 4, 2009 Show us the value of $sql. Link to comment https://forums.phpfreaks.com/topic/156600-problem-using-sql-select-statement-to-define-a-variable-value/#findComment-826105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.