Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:00:59+00:00 2026-06-02T01:00:59+00:00

I have set up a shopping basket which is a session list is stored

  • 0

I have set up a shopping basket which is a session list is stored in a session array called ['list']. I want to extract the session data (information about list items) and insert them into a database table.

session_start();
Print_r ($_SESSION['list']);

if ( !isset($_SESSION['username']) && ($_SESSION['list']) )
{
   header("Location:index.php");
   exit();
}

Result:

Array ( [1] => Array ( [ISBN] => 0923184232 [bookname] => asodiaso [author] => lolstan [price] => 5.99 ) [2] => Array ( [ISBN] => 6677889900 [bookname] => The Templars Code [author] => C.M. Palov [price] => 18.99 ) )

^ I want this information inserted into a table! 🙂

By using this I can print off the session variables contained within the Array but what I need to do is to extract the variables and then insert them into another database table.
I have no idea how to go about extracting them so any suggestions?

I am familiar with how to insert information into the database tables (MYSQL).

The insert method looks like this:

$query = "INSERT INTO orderhistory VALUES ('','".$ISBN."','".$bookname."','".$author."','".$price."', '')";

At the moment my addtobasket.php looks like:

`

require "dbconn.php";

//Connects to database
$connect = mysql_connect($host, $user, $password )
or die ("Hey loser, check your server connection.");

//Make sure we are using the right database
mysql_select_db($database);

$ISBN = $_SESSION['list']['ISBN'];
$bookname = $_SESSION['list']['bookname'];
$author = $_SESSION['list']['author'];
$price = $_SESSION['list']['price'];

// Set up the query using the values that were passed via the URL from the form
$query = "INSERT INTO orderhistory 
VALUES('','".$ISBN."','".$bookname."','".$author."','".$price."', '')"; 

Yes, I know it is wrong! :((

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:01:00+00:00Added an answer on June 2, 2026 at 1:01 am

    If you just want to dump the contents of your variable in a database field, you can use serialize() or json_encode() to convert your array to a string that you can easily convert back.

    By the way, I would strongly suggest switching to PDO and prepared statements to avoid the basic sql injection problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a shopping cart stored in session which decreases quantities of items stored
I have 2 lists. A shopping cart list, which contains a objects with the
I have a MySQL shopping basket set up. There are 11 products in total
I have set my default RVM to ruby 1.9.2 . I want to remove
I have some delphi code which, given a list of items, calculates the total
I have a shopping cart of products (called line_items), and I'm trying to add
I have a Session which I am using to hold items in a form
I am currently developing a shopping cart solution and I have a field, which
We have a Magento Shop and the shipping settings are already set and everything
I have set up the Nginx +unicorn for my rails application, it is working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.