Shopping cart for multiple tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashraf02
    New Member
    • Feb 2008
    • 53

    Shopping cart for multiple tables

    basicaly i am creating a shopping cart for my website however creating a shopping cart for one table of items is easy but can someone direct me on how to create a shopping cart that can handle more than one table of items. i really need ur help on this

    thanks

    ashraf
  • ashraf02
    New Member
    • Feb 2008
    • 53

    #2
    to elaborate further on my problem i am trying to execute the code below there are two seperate item tables. 1, shirts 2, trousers and i am trying to integrate it so that when customers select the item it would appear on the shopping basket even though there arein seperate tables. hope this makes sense.

    Code:

    [PHP]<?php
    session_start() ;

    $conn = mysql_connect(" localhost", "root", "")
    or die (mysql_error()) ;
    mysql_select_db ("noble", $conn) or die (mysql_error()) ;

    if ($_POST[Bas_Item_ID] != "") {
    $shirt_info = "SELECT Shirt_Brand
    FROM Shirts
    WHERE Shirt_ID =$_POST[Bas_Item_ID]";
    $shirt_info_res = mysql_query ($shirt_info) or die (mysql_error()) ;

    if (mysql_num_rows ($shirt_info_re s) < 1) {
    header ("Location: Display_Smart.p hp");
    exit;
    } else {
    $trouser_info = "SELECT Trouser_Brand
    FROM Trousers
    WHERE Trouser_ID =$_POST[Bas_Item_ID]";
    $trouser_info_r es = mysql_query ($trouser_info) or die (mysql_error()) ;

    if (mysql_num_rows ($trouser_info_ res) < 1) {
    header ("Location: Display_Smart.p hp");
    exit;
    } else {
    $trouser_brand = mysql_result($t rouser_info_res ,0,'Trouser_Bra nd');
    $shirt_brand = mysql_result($s hirt_info_res,0 ,'Shirt_Brand') ;
    }
    $addcart = "INSERT INTO Basket
    VALUES ('','$[COOKIE]PHPSESSID', '$_POST[Bas_Item_ID]', '$_POST[Bas_Item_Qty]', '$_POST[Bas_Item_Size]',
    now())";

    mysql_query($ad dcart);

    header("locatio n: Showcart.php");
    exit;

    }

    } else {
    header ("Location: Display_Smart.p hp");
    exit;
    }

    ?>[/PHP]

    thanks in advance

    Comment

    • ashraf02
      New Member
      • Feb 2008
      • 53

      #3
      ive updated the code so that the shirts can go through to the basket but when i try putting the trousers through the basket nothng happens. please please please help it's urgent.

      ashraf

      updated code[php]
      <?php
      session_start() ;
      $conn = mysql_connect(" localhost", "root", "")
      or die (mysql_error()) ;
      mysql_select_db ("noble", $conn) or die (mysql_error()) ;
      if ($_POST[Bas_Item_ID] != "") {
      $shirt_info = "SELECT Shirt_Brand
      FROM Shirts
      WHERE Shirt_ID =$_POST[Bas_Item_ID]";
      $shirt_info_res = mysql_query ($shirt_info) or die (mysql_error()) ;

      if (mysql_num_rows ($shirt_info_re s) < 1) {
      header ("Location: Display_Smart.p hp");
      exit;
      } else {
      $shirt_brand = mysql_result($s hirt_info_res,0 ,'Shirt_Brand') ;
      $addcart = "INSERT INTO Basket
      VALUES ('','$[COOKIE]PHPSESSID', '$_POST[Bas_Item_ID]', '$_POST[Bas_Item_Qty]', '$_POST[Bas_Item_Size]',
      now())";
      mysql_query($ad dcart);
      header("locatio n: Showcart.php");
      exit;
      }
      if ($_POST[Bas_Item_ID] != "") {
      $trouser_info = "SELECT Trouser_Brand
      FROM Trousers
      WHERE Trouser_ID = $_POST[Bas_Item_ID]";
      $trouser_info_r es = mysql_query ($trouser_info) or die (mysql_error()) ;
      if (mysql_num_rows ($trouser_info_ res) < 1) {
      header ("Location: Display_Smart.p hp");
      exit;
      } else {
      $trouser_brand = mysql_result($t rouser_info_res ,0,'Trouser_Bra nd');

      $addcart = "INSERT INTO Basket
      VALUES ('','$[COOKIE]PHPSESSID', '$_POST[Bas_Item_ID]', '$_POST[Bas_Item_Qty]', '$_POST[Bas_Item_Size]',
      now())";
      mysql_query($ad dcart);
      header("locatio n: Showcart.php");
      exit;
      }
      } else {
      header ("Location: Display_Smart.p hp");
      exit;
      }
      }
      ?>[/php]
      Last edited by ronverdonk; Apr 10 '08, 09:34 PM. Reason: warning: use code tags!

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        As a full member now, you should know that we expect your code to be posted in [CODE] tags (See How to Ask a Question).

        This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

        Please use the tags in future.

        MODERATOR.

        Comment

        • ashraf02
          New Member
          • Feb 2008
          • 53

          #5
          i apologise it was a mistake. any chance u could help me with my code though i am gettin really frustrated and dont know wat to do.

          Comment

          • TheServant
            Recognized Expert Top Contributor
            • Feb 2008
            • 1168

            #6
            I am not following what the problem is... Also, I am confused why you only have one POST variable (Bas_Item_ID). Both if statements are the same:
            6. if ($_POST[Bas_Item_ID] != "") {
            24. if ($_POST[Bas_Item_ID] != "") {

            What error are you getting? What exactly is coming up, or not coming up?

            Comment

            • ashraf02
              New Member
              • Feb 2008
              • 53

              #7
              for the the shirt table i can go through to the checkout basket but for the trousers table it comes up with a blank screen and i want both items to be added to the cart but only one table allows it. is there anyway i can add extra code to allow trousers to go through to the cart.

              Comment

              • code green
                Recognized Expert Top Contributor
                • Mar 2007
                • 1726

                #8
                You have a blank screen because you have no error checking or echo statements.
                I have looked at the code and it is quite obvious what is happening -
                If you don't buy a shirt the script exits.
                As TheServant pointed out, one POST variable is used for both shirts and trousers.
                Now please put some error checking and echo statements in your code

                Comment

                • ashraf02
                  New Member
                  • Feb 2008
                  • 53

                  #9
                  thanks for the response i have updated the code which looks like this :

                  [PHP]
                  <?php

                  session_start() ;

                  $conn = mysql_connect(" localhost", "root", "")

                  or die (mysql_error()) ;

                  mysql_select_db ("noble", $conn) or die (mysql_error()) ;

                  if ($_POST[Bas_Item_ID] != "") {

                  $shirt_info = "SELECT Shirt_Brand

                  FROM Shirts

                  WHERE Shirt_ID =$_POST[Bas_Item_ID]";

                  $shirt_info_res = mysql_query ($shirt_info) or die (mysql_error()) ;
                  if (mysql_num_rows ($shirt_info_re s) < 1) {
                  die (mysql_error()) ;
                  exit;
                  } else {
                  $shirt_brand = mysql_result($s hirt_info_res,0 ,'Shirt_Brand') ;
                  }
                  $trouser_info = "SELECT Trouser_Brand
                  FROM Trousers
                  WHERE Trouser_ID = $_POST[Bas_Item_ID]";
                  $trouser_info_r es = mysql_query ($trouser_info) or die (mysql_error()) ;
                  if (mysql_num_rows ($trouser_info_ res) < 1) {
                  die (mysql_error()) ;
                  exit;
                  } else {
                  $trouser_brand = mysql_result($t rouser_info_res ,0,'Trouser_Bra nd');

                  $addcart = "INSERT INTO Basket
                  VALUES ('','$[COOKIE]PHPSESSID', '$_POST[Bas_Item_ID]', '$_POST[Bas_Item_Qty]', '$_POST[Bas_Item_Size]',
                  now())";
                  mysql_query($ad dcart);
                  header("locatio n: Showcart.php");
                  exit;
                  }
                  } else {
                  header ("Location: Display_Smart.p hp");
                  exit;
                  }
                  ?>[/PHP]

                  the error i get is :

                  Warning: session_start() [function.sessio n-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\add tocart.php:2) in C:\wamp\www\add tocart.php on line 4

                  Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\add tocart.php:2) in C:\wamp\www\add tocart.php on line 45
                  Last edited by ronverdonk; Apr 11 '08, 10:19 AM. Reason: bold text tags removed

                  Comment

                  • code green
                    Recognized Expert Top Contributor
                    • Mar 2007
                    • 1726

                    #10
                    This means you are trying to send header information to the browser
                    when output has already been sent or header information has already been sent.

                    Comment

                    • ashraf02
                      New Member
                      • Feb 2008
                      • 53

                      #11
                      how can i sort this problem out

                      Comment

                      • code green
                        Recognized Expert Top Contributor
                        • Mar 2007
                        • 1726

                        #12
                        how can i sort this problem out
                        Well, all the information is in the error message.
                        On which line the problem occurred and in which file.
                        You cannot send multiple header information to a browser

                        Comment

                        Working...