danielwimberley
asked on
Trying to insert $PHPSESSID as session_id into mysql
I'm a newbie at this. Trying to build a shopping cart. Using source code from a book, running into 2 scenarios:
A: PHPSESSID does not insert into MySQL, so my viewcart page shows all records lacking a session_id.
B: If I use $_POST[.session_id().], it is inserted into MySQL, but my cart shows empty. I've been jacking with this for 2 days now. Here is my source code...
session_start();
$conn = mysql_connect("localhost", "Root", "")
or die(mysql_error());
mysql_select_db("AWS",$con n) or die(mysql_error());
if ($_POST[sel_templ_id] != "") {
$get_templinfo = "select templ_title from template where id = $_POST[sel_templ_id]";
$get_templinfo_res = mysql_query($get_templinfo ) or die(mysql_error());
if (mysql_num_rows($get_templ info_res) < 1) {
header("Location: category.php");
exit;
} else {
$templ_title = mysql_result($get_templinf o_res,0,'t empl_title ');
$addtocart = "insert into templ_shoppertrack values ('$_POST[sel_templ_id]', '$PHPSESSID', now())";
mysql_query($addtocart);
header("Location: showcart.php");
exit;
}
} else {
header("Location: category.php");
exit;
}
In case you need to know this, I'm using PHP 4.3.3 and mysql 4.0.15.
Any suggestions? Thanks!
A: PHPSESSID does not insert into MySQL, so my viewcart page shows all records lacking a session_id.
B: If I use $_POST[.session_id().], it is inserted into MySQL, but my cart shows empty. I've been jacking with this for 2 days now. Here is my source code...
session_start();
$conn = mysql_connect("localhost",
or die(mysql_error());
mysql_select_db("AWS",$con
if ($_POST[sel_templ_id] != "") {
$get_templinfo = "select templ_title from template where id = $_POST[sel_templ_id]";
$get_templinfo_res = mysql_query($get_templinfo
if (mysql_num_rows($get_templ
header("Location: category.php");
exit;
} else {
$templ_title = mysql_result($get_templinf
$addtocart = "insert into templ_shoppertrack values ('$_POST[sel_templ_id]', '$PHPSESSID', now())";
mysql_query($addtocart);
header("Location: showcart.php");
exit;
}
} else {
header("Location: category.php");
exit;
}
In case you need to know this, I'm using PHP 4.3.3 and mysql 4.0.15.
Any suggestions? Thanks!
ASKER
Tried your suggestions...seems like one or all should've worked, but now no records are being added, and my shopping cart shows empty. Before a record was added, just minus the session_id.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tried this and praise God, it worked! Thanks so much for the help.
$addtocart = "insert into templ_shoppertrack values ('$_POST[sel_templ_id]', '".session_id()."', now())";
or
$PHPSESSID = session_id();
$addtocart = "insert into templ_shoppertrack values ('$_POST[sel_templ_id]', '$PHPSESSID', now())"; /* This is your original line */