Solved

Trying to insert $PHPSESSID as session_id into mysql

Posted on 2004-08-28
4
580 Views
Last Modified: 2014-11-12
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!
0
Comment
Question by:danielwimberley
  • 2
4 Comments
 
LVL 7

Expert Comment

by:aib_42
ID: 11924381
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 */
0
 

Author Comment

by:danielwimberley
ID: 11924443
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.
0
 
LVL 26

Accepted Solution

by:
ushastry earned 500 total points
ID: 11924854
Try this..

$sessID = session_id();
session_start();

$conn = mysql_connect("localhost", "Root", "")
or die(mysql_error());
mysql_select_db("AWS",$conn) or die(mysql_error());

$sel_templ_id = $_POST['sel_templ_id'];

if (isset($sel_templ_id))
{
    $get_templinfo = "select templ_title from template where id ='$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 ('$sel_templ_id', '$sessID', now())";
         
           mysql_query($addtocart);

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

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



0
 

Author Comment

by:danielwimberley
ID: 11927147
Tried this and praise God, it worked! Thanks so much for the help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Happy holidays! Your Ops team can pack their bags. IT management and IT management tools are dead. Or at least that’s according to a new blog from Tech Target on AWS’s new Managed Services (MS) offering.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now