Jump to content

Mysql Checkout

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Mysql Checkout Rate Topic: -----

#1 User is offline   Man2u2uk 

  • W.R. Lieutenant
  • Group: Members
  • Posts: 396
  • Joined: 14-April 07
  • Gender:Male

Posted 04 May 2007 - 08:59 AM

i am currently struggling with my online shop checkout.....

at the moment i have 4 product pages.....

each product on these pages has an "ADD" button next to it, "'<a href ="cart.php?action=addprod&prodcode='.$prod_id.' ">Add</a>'; ?>" which then takes the products unique prod_id and transfers it to the cart.

the on my cart page i have following.

<?session_start();?>[/b] // At the top of the page.

followed by:

[b]if ( ( isset( $_REQUEST['action'] ) ) && ( isset( $_REQUEST['prodcode'] ) ) )
{
	$code = $_REQUEST['prodcode'];
	
	 if ( $_REQUEST['action'] == "addprod" )
	{
		$_SESSION['cart'][ $code ] = array(
			'prodcode' => $code,
			'quantity' => 1,
		);

	}
	
}
 if ( $_REQUEST['action'] == "empty" )
 session_unset();
echo "<pre>\n";
print_r( $_SESSION );
echo "</pre>\n"; 
?>

This does work, it displays the prod_id which it got from the product page and also the quantity of 1, (which i hard coded)

my problem is: how could i connect this to my database to get te rest of the product info?

and how can i make the cart look better, as because i am currently printing the array it looks like this:

Array
(
	[cart] => Array
		(
			[RUG254CD] => Array
				(
					[prodcode] => RUG254CD
					[quantity] => 1
				)

		)

)

0

#2 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 04 May 2007 - 10:01 AM

View PostMan2u2uk, on May 4 2007, 02:59 PM, said:

my problem is: how could i connect this to my database to get te rest of the product info?

im guessing you want this for a view cart feature?

well, you could do a while loop to run through the ids of the session and gather them into one string and then do a quick sql query..

SELECT * FROM table_name WHERE prodcode IN (  123456789,abcdefghij, qwertyuiop11,  )


So whats in the brackets, will only select records that have those prodcodes.

Hope this makes sense..can explain in better detail if not

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#3 User is offline   Man2u2uk 

  • W.R. Lieutenant
  • Group: Members
  • Posts: 396
  • Joined: 14-April 07
  • Gender:Male

Posted 04 May 2007 - 10:23 AM

Well at the moment because i am printing the whole session.

echo "<pre>\n";
print_r( $_SESSION );
echo "</pre>\n";


the display looks like this:

Array
(
[cart] => Array
(
[RUG254CD] => Array
(
[prodcode] => RUG254CD
[quantity] => 1
)

)

which does not look very nice, how can i just make it look like:
[prodcode] => RUG254CD
[quantity] => 1

)

0

#4 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 04 May 2007 - 05:51 PM

can you use code tags inf future please Man2u2uk? They Its easier for a lot of reasons..

Back on topic, why would you want to print out an array? what reason is there to do this? There is no "nice" way to print out an array unless you grab it and do something to the arrays contents first.

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#5 User is offline   Man2u2uk 

  • W.R. Lieutenant
  • Group: Members
  • Posts: 396
  • Joined: 14-April 07
  • Gender:Male

Posted 05 May 2007 - 03:27 AM

Sorry for not using the code tags, my bad :(

to be honest i do not know anything about php, so i do not know whats right or wrong....

all i know is that i need to get my products from my product page to the cart, then allow the user to input their billing address then upload it to a database on submit of the form
0

#6 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 05 May 2007 - 10:02 AM

View PostMan2u2uk, on May 5 2007, 09:27 AM, said:

Sorry for not using the code tags, my bad :(

to be honest i do not know anything about php, so i do not know whats right or wrong....

all i know is that i need to get my products from my product page to the cart, then allow the user to input their billing address then upload it to a database on submit of the form

dont they need some kind of "view cart" page? then from there, you can easily enter billing details etc..

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#7 User is offline   Man2u2uk 

  • W.R. Lieutenant
  • Group: Members
  • Posts: 396
  • Joined: 14-April 07
  • Gender:Male

Posted 05 May 2007 - 10:38 AM

Yes they do have that page.

i currently have the following

Product Page -> Cart -> Checkout

my products display properly on my product page, i just need to get them into my cart and then into the checkout.
0

#8 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 05 May 2007 - 12:18 PM

View PostMan2u2uk, on May 5 2007, 04:38 PM, said:

Yes they do have that page.

i currently have the following

Product Page -> Cart -> Checkout

my products display properly on my product page, i just need to get them into my cart and then into the checkout.

hen do the method i described above, to get a string of numbers and do a query to select all records with those id's. Thats the basis for your basket page, then, its easy to check out the product from that page.

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#9 User is offline   Man2u2uk 

  • W.R. Lieutenant
  • Group: Members
  • Posts: 396
  • Joined: 14-April 07
  • Gender:Male

Posted 05 May 2007 - 01:16 PM

I understand what your saying, but i just do not know how to actual do it...

at the moment my viewcart page looks like this.

if ( ( isset( $_REQUEST['action'] ) ) && ( isset( $_REQUEST['prodcode'] ) ) )
{
    $code = $_REQUEST['prodcode'];
    
     if ( $_REQUEST['action'] == "addprod" )
    {
        $_SESSION['cart'][ $code ] = array(
            'prodcode' => $code,
            'quantity' => 1,
        );

    }
    
}
if ( $_REQUEST['action'] == "empty" )
session_unset();
echo "<pre>\n";
print_r( $_SESSION );
echo "</pre>\n";
?>


by reading what your saying, i need to somewhere in this code, loop through my session and grab all the prod codes?

then connect to my database and query it using the prodcode for the rest of each products information.

then echo it all into a table?

i know this is really easy to do, sorry if i am wrong again, but i am a PHP n00b
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users