SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Moving variables from one page to another

    Hi everyone

    I'm creating a mock online store and because security considerations arent a worry I'm going to store customer details, card numbers etc in a database.

    I've got everything up to the cart working and I'm at the checkout stage. I wanted to carry the values of the total cost and customer id from the cart to the order submit page.

    I'm pretty new to this and I just wanted to know the best way to transfer the $total variable and the $customer id variable to the next page.

    I presume they will be stored in a session. I'm struggling with the code to transfer the values to the next stage of the process. This is the code I'musing but i've just inserted mock values into the $total and $customer variables.

    PHP Code:
    <?php

    $page_title 
    'Order Confirmation';
    include (
    './includes/header.html');

    $customer 1

    $total 178.93

    require_once (
    '../mysql_connect.php'); 

    mysql_autocommit($dbcFALSE);

    $query "INSERT INTO orders (customer_id, total) VALUES ($customer$total)";
    $result mysql_query($query);
    if (
    mysql_affected_rows($dbc) == 1) {

        
    $oid mysql_insert_id($dbc);
        
        
    $query "INSERT INTO order_contents (order_id, product_id, quantity, price) VALUES ";
        foreach (
    $_SESSION['cart'] as $pid => $value) {
            
    $query .= "($oid$pid{$value['quantity']}{$value['price']}), ";
        }
        
    $query substr($query0, -2); 
        
    $result mysql_query($query);
        
        
        if (
    mysql_affected_rows($dbc) == count($_SESSION['cart'])) { 
        
            
    mysql_commit($dbc);
            
    mysql_close($dbc);
            
            
            unset(
    $_SESSION['cart']);
            
            
            echo 
    '<p>Thank you for your order. You will be notified when the items ship.</p>';
            
            
        
        } else { 
        
            
    mysql_rollback($dbc);
            
    mysql_close($dbc);
            
            echo 
    '<p>Your order could not be processed due to a system error. You will be contacted in order to have the problem fixed. We apologize for the inconvenience.</p>';
            
            
        }

    } else { 

        
    mysql_rollback($dbc);
        
    mysql_close($dbc);

        echo 
    '<p>Your order could not be processed due to a system error. You will be contacted in order to have the problem fixed. We apologize for the inconvenience.</p>';
    }

    include (
    './includes/footer.html');
    ?>
    Also, do I have to change any settings on MySQL for autocommit to work? Thank you for your help in advance.

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    You need session_start(); at the top of the script unless it's included in the header.html file (I'm guessing it isn't as it's an html file)

    Also I would reconsider storing users credit cards details in a database as it's a huge security factor. There was a thread recently which I will dig out for you to read.

    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •