Link to home
Start Free TrialLog in
Avatar of danielwimberley
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",$conn) 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_templinfo_res) < 1) {

             header("Location: category.php");
             exit;
    } else {

             $templ_title =  mysql_result($get_templinfo_res,0,'templ_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!
Avatar of aib_42
aib_42

Try session_id(). As itself. Even $_POST['PHPSESSID'] might work, but I'm not sure where "$_POST[.session_id().]" comes from.

$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 */
Avatar of danielwimberley

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
Avatar of Umesh
Umesh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tried this and praise God, it worked! Thanks so much for the help.