General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 12th, 2004, 05:58 PM
Archer36 Archer36 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: USA, Michigan
Posts: 4 Archer36 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Archer36 Send a message via AIM to Archer36
Question Checkout Page Help

Hello,
Im still a PHP newb, but i got a shopping cart script up and running on my web server it is the one from here URL it works great but i want it to do one more thing but i do not know how to make it do that.

What i want is to make a checkout page that would e-mail me all the contents of the shopping cart, and tell me what the user bought and how much each item is, ect. I do not know how to make it do that, Again the code is just like the code on the Macromedia site, down to the table names.

This is my Order Table layout:

order_id int(11) No auto_increment
order_date date No 0000-00-00
order_qty tinyint(4) No 0
order_price decimal(4,2) No 0.00
user_id int(11) No 0
itemId int(11) No 0

This is my User table:

user_id int(11) No auto_increment
user_name varchar(50) No
user_email varchar(100) No
user_address varchar(120) No
user_city varchar(60) No
user_nhood varchar(60) No
user_zip varchar(5) No
user_country varchar(60) No
user_pass varchar(30) No
user_phone varchar(14) No

And that is as far as i can get.

here is my code::





Code:
<?php


	include("db.php");

	switch($_GET["action"])
	{
		case "add_item":
		{
			AddItem($_GET["id"], $_GET["qty"]);
			ShowCart();
			break;
		}
		case "update_item":
		{
			UpdateItem($_GET["id"], $_GET["qty"]);
			ShowCart();
			break;
		}
		case "remove_item":
		{
			RemoveItem($_GET["id"]);
			ShowCart();
			break;
		}
		default:
		{
			ShowCart();
		}
	}

	function AddItem($itemId, $qty)
 	{
		// Will check whether or not this item
		// already exists in the cart table.
		// If it does, the UpdateItem function
		// will be called instead

		global $dbServer, $dbUser, $dbPass, $dbName;

		// Get a connection to the database
		$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

		// Check if this item already exists in the users cart table
		$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId" );
		$row = mysql_fetch_row($result);
		$numRows = $row[0];

		if($numRows == 0)
		{
			// This item doesn't exist in the users cart,
			// we will add it with an insert query

			@mysql_query("insert into cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)");
		}
		else
		{
			// This item already exists in the users cart,
			// we will update it instead

			UpdateItem($itemId, $qty);
		}
	}

	function UpdateItem($itemId, $qty)
	{
		// Updates the quantity of an item in the users cart.
		// If the qutnaity is zero, then RemoveItem will be
		// called instead

		global $dbServer, $dbUser, $dbPass, $dbName;

		// Get a connection to the database
		$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
		
		if($qty == 0)
		{
			// Remove the item from the users cart
			RemoveItem($itemId);
		}
		else
		{
			mysql_query("update cart set qty = $qty where cookieId = '" . GetCartId() . "' and itemId = $itemId");
		}

	}
	
	function RemoveItem($itemId)
	{
		// Uses an SQL delete statement to remove an item from
		// the users cart

		global $dbServer, $dbUser, $dbPass, $dbName;

		// Get a connection to the database
		$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
		
		mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
	}
	
	function ShowCart()
	{
		// Gets each item from the cart table and display them in
		// a tabulated format, as well as a final total for the cart
		
		global $dbServer, $dbUser, $dbPass, $dbName;

		// Get a connection to the database
		$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
		
		$totalCost = 0;
		$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemPrice asc");
		?>
		<html>
		<head>
		<title> Your Shopping Cart </title>
		<script language="JavaScript">
		
			function UpdateQty(item)
			{
				itemId = item.name;
				newQty = item.options[item.selectedIndex].text;

				document.location.href = 'order.php?action=update_item&id='+itemId+'&qty='+newQty;
			}
		
		</script>
		</head>
		<body bgcolor="#ffffff">

		<form name="frmCart" method="get">
		<table align="left" width="80%" cellspacing="0" cellpadding="0" border="0">
			<tr>
				<td width="15%" height="25" bgcolor="red">
					<font face="verdana" size="1" color="white">
						&nbsp;&nbsp;<b>Qty</b>
					</font>
				</td>
				<td width="55%" height="25" bgcolor="red">
					<font face="verdana" size="1" color="white">
						<b>Product</b>
					</font>
				</td>
				<td width="20%" height="25" bgcolor="red">
					<font face="verdana" size="1" color="white">
						<b>Price Each</b>
					</font>
				</td>
				<td width="10%" height="25" bgcolor="red">
					<font face="verdana" size="1" color="white">
						<b>Remove?</b>
					</font>
				</td>

			</tr>
			<?php

			while($row = mysql_fetch_array($result))
			{
				// Increment the total cost of all items
				$totalCost += ($row["qty"] * $row["itemPrice"]);
				?>
					<tr>
						<td width="15%" height="25">
							<font face="verdana" size="1" color="black">
								<select name="<?php echo $row["itemId"]; ?>" onChange="UpdateQty(this)">
								<?php

									for($i = 1; $i <= 20; $i++)
									{
										echo "<option ";
										if($row["qty"] == $i)
										{
											echo " SELECTED ";
										}
										echo ">" . $i . "</option>";
									}
								?>
								</select>
							</font>
						</td>
						<td width="55%" height="25">
							<font face="verdana" size="1" color="black">
								<?php echo $row["itemName"]; ?>
							</font>
						</td>
						<td width="20%" height="25">
							<font face="verdana" size="1" color="black">
								$<?php echo number_format($row["itemPrice"], 2, ".", ","); ?>
							</font>
						</td>
						<td width="10%" height="25">
							<font face="verdana" size="1" color="black">
								<a href="order.php
								?action=remove_item&id=<?php echo $row["itemId"]; ?>">Remove</a>
							</font>
						</td>
					</tr>
				<?php
			}

			// Display the total
			?>
					<tr>
						<td width="100%" colspan="4">
							<hr size="1" color="red" NOSHADE>
						</td>
					</tr>
					<tr>
						<td width="33%" colspan="1">
							<font face="verdana" size="1" color="black">
								<a href="products.php"><< Keep Shopping</a>
							</font>
						</td>
						<td width="25%" colspan="1">
							<font face="verdana" size="2" color="black">
								<b>Total: $<?php echo number_format($totalCost, 2, ".", ","); ?></b>
							</font>
						</td>
						<td width="33%" colspan="2">
							<font face="verdana" size="1" color="black">
								<a href="checkout.php">Checkout >></a>
							</font>
						</td>

					</tr>
				</table>
				</form>
			</body>
			</html>
			<?php
	}

?>

Reply With Quote
  #2  
Old January 12th, 2004, 10:19 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
There's a handy PHP function that isn't hard to implement...
http://www.php.net/manual/en/function.mail.php

If you're running it on your home machine, you may need to set up a mail server...

Here's a helpful thread that may assist you:
http://forums.devarticles.com/showt...ght=mail+server

Reply With Quote
  #3  
Old January 12th, 2004, 10:24 PM
Archer36 Archer36 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: USA, Michigan
Posts: 4 Archer36 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Archer36 Send a message via AIM to Archer36
yes, the mail function but what would i put in the function to make is send the the contents of the cart back? Would it be a form varable of some sort like in my code i posted down
Code:
form name="frmCart" method="get">

Is there a way to chage the port on which sendmail operates? Because im almost + that my ISP Charter Comm. blocks those ports. Im running The Fedora Core on my box.

Reply With Quote
  #4  
Old January 12th, 2004, 10:34 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Sorry, I underestimated you... =)

I would suggest coding it (in PHP) inside your AddCart() function... after you insert the information into the database, format a string with all the information you want to see then mail() it to yourself (or wherever)


As far as sendmail goes... Edit sendmail.cf and look for this
DaemonPortOptions=Port=smtp,Addr=127.0.0.1, Name=MTA

Replace Port=smtp with Port=125

Reply With Quote
  #5  
Old January 12th, 2004, 10:54 PM
Archer36 Archer36 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: USA, Michigan
Posts: 4 Archer36 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Archer36 Send a message via AIM to Archer36
ok i must be missing something i have no AddCart() function i do have AddItem though. Otherwise i think i got it from there. For the string i would put in
Code:
$row["itemId"]; $row["itemName"]; $row["itemPrice"];
correct? but some how i would have to extract that from the users Cookie i think?

Reply With Quote
  #6  
Old January 12th, 2004, 11:14 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Sorry, my mistake... I meant AddCart()

the information in your insert statement is: GetCartId(), $itemId, $qty

You could simply email yourself that information, or submit another query to the database (based on the CartId) and email those results...

Reply With Quote
  #7  
Old January 13th, 2004, 03:11 PM
Archer36 Archer36 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: USA, Michigan
Posts: 4 Archer36 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Archer36 Send a message via AIM to Archer36
Yea thanks ill try that in a few minutes.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Checkout Page Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT