Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Trying to insert $PHPSESSID as session_id into mysql

Posted on 2004-08-28
4
Medium Priority
?
597 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:
Umesh earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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…
Suggested Courses

810 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