Jump to content

gex80

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

gex80's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok I basically want to build a simple php shopping cart. I already have a database with products and product IDs, and each product page has their product ID associated with it by asking the database for it's ID. Now how would I go about building a shopping cart? I already researched sessions and cookies and came to the conclusion that a session would be best since not all browsers use cookies or have them turned on. I how ever don't understand how to use sessions for a shopping cart. I know the first line the code in my php document has to have session_start(); How do I go about adding values to the session?
  2. Thanks it was $rmanumber that was causing the problem. I guess it's better off that it isn't random then.
  3. I would assume that in your mysql query you use the sort function with a where clause. then it would save it to the array in the order that it is sorted in. What I would do is first echo out the sql results to see if it is in the order you want and then after that pass it into an array.
  4. Hi, I'm still new to php and having some problems. Sorry about the code not being formatted properly. The snippet I posted has both the code intend to work but it is commented out and a test version that has an array already set thus getting rid of the need of setting up every thing like I have. Ok this is basically my problem. I'm building a store like website. Its suppose to be very basic for now Part of the website is an RMA system where the customer enters an order number and then pulls up all items in the order on a different page in a table format with check boxes next to each item found in the database. Each item that is checked off is then saved to an array rma[] which posts to another page when submitted. What this page(copied down below) does is it pulls values from the cookie already made and creates new variables which is not a problem. After that it does a foreach loop for the array of the items into a mysql query which then is suppose to insert it into a database. When the code runs it only inserts the first item in the array into the database no matter how many items are in the array. When I echo the $insert statement I get this(using the test code) like I expect I'm suppose to. I would assume that because I'm doing a foreach loop that it is doing an INSERT for the number of items in the array. <?php //connects to the data base mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("project") or die(mysql_error()); /* //retrieving rma array from previous page $rmarequest = $_POST['rma']; //retieves using name from cookie $username = $_COOKIE['ID_my_site']; //retrieves order number from cookie $ordernumber = $_COOKIE['order']; //creates rma number $rmanumber = rand(1000, 999999); //retrieves accountid from database using the username $getid = mysql_query("SELECT AccountID FROM users WHERE username = '$username'"); $id = mysql_fetch_array( $getid ); //takes the value of $id $final = $id['AccountID']; //suppose to loop through all values for the array created by $request on the previous page and insert into database foreach($rmarequest as $key){ // $insert = "INSERT INTO `project`.`rma` (rmanumber, AccountID, item, ordernumber) VALUES ('".$rmanumber."', '".$AccountID."','".$key."','".$ordernumber."')"; //mysql_query($insert) OR die(mysql_error()); //this is test to see what is being passed to mysql server $insert = "INSERT INTO `project`.`rma` (rmanumber, AccountID, item, ordernumber) VALUES ('".$rmanumber."', '1','".$key."','123')"; //mysql_query($insert) OR die(mysql_error()); //to view what $insert is passing to the data base. echo $insert;} */ //THIS SECTION IS TEST ONLY //test array $cars[0]="Saab"; $rmarequest[1]="Volvo"; $rmarequest[2]="BMW"; $rmarequest[3]="Toyota"; //creates rma number $rmanumber = rand(1000, 999999); foreach($rmarequest as $key){ //this is test to see what is being passed to mysql server $insert = "INSERT INTO `project`.`rma` (rmanumber, AccountID, item, ordernumber) VALUES ('".$rmanumber."', '1','".$key."','123')"; mysql_query($insert) OR die(mysql_error()); //to view what $insert is passing to the data base. echo $insert."<br />"; } ?> Included is a copy of the table and the php code above. [attachment deleted by admin]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.