Solved

Trying to insert $PHPSESSID as session_id into mysql

Posted on 2004-08-28
4
579 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Tried this and praise God, it worked! Thanks so much for the help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Security is one of the biggest concerns when moving and migrating your data from your on-premise location to the Public Cloud.  Where is your data? Who can access it? Will it be safe from accidental deletion?  All of these questions and more are imp…
Monitoring systems evolution, cloud technology benefits and cloud cost calculators business utility.
The viewer will learn how to count occurrences of each item in an array.
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…

744 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

15 Experts available now in Live!

Get 1:1 Help Now