PHP Insert of session variable

I have a form that collects data from the end user inputting the data. I also have a session script to check if the end user logged in so that the page will display or forward them somewhere else.

The form page will go to a INSERT.php which inserts the form variables into the database. What I need to do is INSERT the session variable which is the username into the database. But I'm getting an error message.

Here is the error message;

Parse error: syntax error, unexpected ',' in /home2/thstew/public_html/insert.php on line 17

Now if I run the same POST Variables without the session variable it works.


Thanks,
Jeff
/// This code is the session variable on the form page// 
<?php
 
 
//Start session
session_start();
//Check whether the session variable
//SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) {
header("location: http://www.google.com");
exit();
}
 
?>
 
//This code is the INSERT STATEMENT //
 $sql="INSERT INTO oetable_backup(entry_date,territory,principle,customer,po,part_no,qty,initial_sale,due_to_ship,comm,type_ind,location_ind)
VALUES
('$_POST[entry_date]','$_POST[territory]','$_POST[principle]','$_POST[customer]','$_POST[po]','$_POST[part_no]','$_POST[qty]','$_POST[initial_sale]','$_POST[due_to_ship]','$_POST[comm]','O','$_POST[SESS_MEMBER_ID]')";

Open in new window

jseaman12Asked:
Who is Participating?
 
syedasimmeesaqConnect With a Mentor Commented:
Better yet, if I would be you, I would try to define the varables first and then use them, instead of using post in insert query.
please find the code below.
Hope that helps

<?php
 
 
//Start session
session_start();
//Check whether the session variable
//SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) {
header("location: http://www.google.com");
exit();
}
else
{ 
$entrydate = $_POST['entry_date'];
$territory = $_POST['territory'];
$principle = $_POST['principle'];
$customer  = $_POST['customer'];
$po = $_POST['po'];
$part_no = $_POST['part_no'];
$qty = $_POST['qty'];
$initial_sale = $_POST['initial_sale'];
$due_to_ship = $_POST['due_to_ship'];
$comm = $_POST['comm'];
$O == "0";
$SESS_MEMBER_ID = $_POST['SESS_MEMBER_ID']; 
 
 
$sql="INSERT INTO oetable_backup(entry_date, territory, principle, customer, po, part_no, qty, initial_sale, due_to_ship, comm, type_ind, location_ind)
VALUES
('".$entry_date."', '".$territory."','".$principle."','".$customer."','".$po."','".$part_no."','".$qty."','".$initial_sale."','".$due_to_ship."','".$comm."','".$O."','".$SESS_MEMBER_ID."')";
}
?>

Open in new window

0
 
syedasimmeesaqConnect With a Mentor Commented:
Try this

$sql="INSERT INTO oetable_backup(entry_date,territory,principle,customer,po,part_no,qty,initial_sale,due_to_ship,comm,type_ind,location_ind)
VALUES
('$_POST[entry_date]','$_POST[territory]','$_POST[principle]','$_POST[customer]','$_POST[po]','$_POST[part_no]','$_POST[qty]','$_POST[initial_sale]','$_POST[due_to_ship]','$_POST[comm]','O','$_SESSION[SESS_MEMBER_ID]')";
0
 
jseaman12Author Commented:
I've tried that one before and receive the same error message. So that doesn't work.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
syedasimmeesaqConnect With a Mentor Commented:
what error message are you getting. Could you be more specific.
Thanks
0
 
syedasimmeesaqConnect With a Mentor Commented:
Please try the code below. Also can you tell me if O in this statement is at right place?  Its not getting any value.
$sql="INSERT INTO oetable_backup(entry_date,territory,principle,customer,po,part_no,qty,initial_sale,due_to_ship,comm,type_ind,location_ind)
VALUES
('".$_POST['entry_date']."', '".$_POST['territory']."','".$_POST['principle']."','".$_POST['customer']."','".$_POST['po']."','".$_POST['part_no']."','".$_POST['qty']."','".$_POST['initial_sale']."','".$_POST['due_to_ship']."','".$_POST['comm']."','".O."','".$_POST['SESS_MEMBER_ID']."')";

Open in new window

0
 
jseaman12Author Commented:
I didn't get the answer I needed but that's ok. Thanks for your help and support.
0
All Courses

From novice to tech pro — start learning today.