Jump to content


Photo

i need help again..


  • Please log in to reply
3 replies to this topic

#1 irene169

irene169
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 02 May 2006 - 06:16 PM


again...i have problem in developing the shopping cart...

the database:

create database product;

create table item(
prodID int(5) not null,
prodName varchar(20),
prodPrice float(6),
PRIMARY KEY (prodID)
)TYPE = MyISAM;

insert into item( prodID, prodName, prodPrice)
values(101, 'Kingston', 29.90);

insert into item( prodID, prodName, prodPrice)
values(104, 'Apache', 39.90);

insert into item( prodID, prodName, prodPrice)
values(104, 'Toshiba', 49.90);

insert into item( prodID, prodName, prodPrice)
values(104, 'Panasonic', 39.90);


here is my code:




<html>
<head>
<title>Products</title>

</body>
<p><CENTER><FONT SIZE=+3 FONT COLOR="gold" FACE="Arial"><b><marquee>PRODUCTS ....

PRODUCTS .... PRODUCTS</marquee></b></FONT><CENTER>

<?php
$connection=mysql_connect('localhost','root')
or die ('Unable to connect');

mysql_select_db('product') or die ('Unable to select database!');

$query='SELECT*FROM item';
$result=mysql_query($query)
or die ('Error in query:$query.'.mysql_error());

if (mysql_num_rows($result)> 0)
{
?>
<table border="1" align=center>
<tr><td>&nbsp</td><td><b>ID</b></td><td><b>NAME</b></td><td><b>PRICE</b></td><td><

b>Quantity</b></td></tr>

<?php
while($row=mysql_fetch_row($result))

{
$Id=$row[0];
$prod[$Id]['desc']=$row[1];
$prod[$Id]['price']=$row[2];

echo'<tr><td><a href="description.html"><img src="1.jpg" height="130" width="140"

align="left"></td>';
echo '<td>'.$Id. '</td>';
echo '<td>'.$prod[$Id]['desc'] . '</td>';
echo '<td>'.$prod[$Id]['price'] . '</td>';
echo '<td><form action="cart.php" method="POST">
<input size=3 type="text" name=\"a_qty[".$Id."]\"></td>';
echo '</tr>';
}
?>
<tr><td colspan="3"></td>
<td colspan="2"><input type="submit" name="add" value="Add items to cart"></td>
</form>
</table>

<?php
}
else
{
echo 'No rows Found!';
}
mysql_free_result($result);
mysql_close($connection);
?>
</body>
</head>
</html>


actually...i have no problem with the code above... but can i know... how can i get the quantity being insert in the form...and sent the input into database..??... wat should i do the next?...i mean how can i get the data from the customer after the click "add items to cart" ...??

the assignment question is like this -->

2. Shopping Cart Module(15 Marks)
a. Display the list of products available for the user to buy online. (5 Marks)
b. If he selects items put them in the shopping cart. And display the list of items selected by the customer along with its cost. (5 Marks)
c. Allow the customer to update or clear the shopping cart. (5 Marks)

i have been stucked here..can any1 help me??..please.........



thanks

regards...

irene




#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 02 May 2006 - 06:22 PM

I hate to be a prick but, inserting data into the db, is one of the very basics of PHP/MySQL.

My suggestion, is to check out :

[a href=\"http://www.php.net\" target=\"_blank\"]http://www.php.net[/a]

[a href=\"http://dev.mysql.com/doc/refman/5.0/en/sql-syntax.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/sql-syntax.html[/a]

Good luck with what appears to be, your assignment.
PHP Ninja

#3 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 02 May 2006 - 06:31 PM

well you should have another table to hold the items in the cart. This table should contain an auto_increment field, customer_id, item_id, quantity, and maybe a status field.

When you click add to cart you should go to the shopping cart page and that is where you enter in the data into the new table.

Before you can do this you need to make sure the values you need are in between the <form> tags. Right now you item id is not.

Not sure what else to tell you other than writing it for you.

Ray

#4 irene169

irene169
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 02 May 2006 - 06:51 PM


so...i need to have a new table in my database to accept all the input fr the form and then displaying all the items that the customer's select in the new page......this new page is taking the data from the new table...right??...calculation can be done within this page ya??....coz i need to sum up all the items' cost...

the customer_id in the new table... should i get the data from the session of that page ??...or some where else?....


actually... im quite slow in learning... sorry...

hope u can give me more ideas.....

thanks a lot...

regards..
irene






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users