Solved

Trying to insert $PHPSESSID as session_id into mysql

Posted on 2004-08-28
4
583 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exporting image to excel from php document 10 28
preventing spam with mailto 22 40
AWS Default Security Group Question 3 34
Decrypt string by php 7 33
This article provides a guide on how to optimise your costs within your AWS infrastructure when using some of the common services such as EC2, EBS, S3, Glacier, CloudFront, EIP & ELB.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

825 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