473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

help on online-shopping cart..

hi pipz,

im working on a simple cart, whenever the user click on "add to cart"
link i store the data to mysql. then i display these records using a
table and each row i place "remove" link.

my problem is if the user click "remove" how will i tell mysql what
record to delete?

this is how i display the contents of the basket of the user...
--------------------------------
<?php
$x=0;
$total=0;
while($x<$num){
echo '<tr>';
$type=mysql_result($result,$x,'citemtype');
$item=mysql_result($result,$x,'cref');
$price=mysql_result($result,$x,'cprice');
$total=$total+$price;

echo '<td width="45" align="center" height="12"><b>';
echo '<font face="Verdana" size="1">'.$type.'</font></b></td>';
echo '<td width="131" align="center" height="12"><b>';
echo '<font face="Verdana" size="1">'.$item.'</font></b></td>';
echo '<td width="54" align="center" height="12"><b>';
echo '<font face="Verdana" size="1">'.$price.'</font></b></td>';
echo '<td width="98" align="center" height="12"><b>';
echo '<font face="Verdana" size="1"><a href="rem.php" style="text-
decoration: none">remove</a></font></b></td>';

$x++;
}//end while
?>
---------------

this part is where the user would like to remove a certain item:
echo '<font face="Verdana" size="1"><a href="rem.php" style="text-
decoration: none">remove</a>

currently the contents of rem.php is these:
-------
<html>
<head>
</head>
<body>
<?php
session_start();
$user = $_SESSION['myuser'];
$conn=mysql_connect(.....) or die('server not found');
$db='mydb';
mysql_select_db($db) or die('.: database done exist :.');
$sel="delete from cart where cuser = '$user'";
$result=mysql_query($sel) or die('.: can\'t perform the query :.');
mysql_close();
?>
<script type="text/javascript">
window.location="basket.php";
</script>
</body>
</html>

since i dont know yet how to remove an item individually..i erase them
all.

Apr 16 '07 #1
15 1890
On Apr 16, 4:54 am, "shotokan99" <soft_devj...@yahoo.comwrote:
hi pipz,

im working on a simple cart, whenever the user click on "add to cart"
link i store the data to mysql. then i display these records using a
table and each row i place "remove" link.

my problem is if the user click "remove" how will i tell mysql what
record to delete?

this is how i display the contents of the basket of the user...
--------------------------------
<?php
$x=0;
$total=0;
while($x<$num){
echo '<tr>';
$type=mysql_result($result,$x,'citemtype');
$item=mysql_result($result,$x,'cref');
$price=mysql_result($result,$x,'cprice');
$total=$total+$price;

echo '<td width="45" align="center" height="12"><b>';
echo '<font face="Verdana" size="1">'.$type.'</font></b></td>';
echo '<td width="131" align="center" height="12"><b>';
echo '<font face="Verdana" size="1">'.$item.'</font></b></td>';
echo '<td width="54" align="center" height="12"><b>';
echo '<font face="Verdana" size="1">'.$price.'</font></b></td>';
echo '<td width="98" align="center" height="12"><b>';
echo '<font face="Verdana" size="1"><a href="rem.php" style="text-
decoration: none">remove</a></font></b></td>';

$x++;}//end while

?>
---------------

this part is where the user would like to remove a certain item:
echo '<font face="Verdana" size="1"><a href="rem.php" style="text-
decoration: none">remove</a>

currently the contents of rem.php is these:
-------
<html>
<head>
</head>
<body>
<?php
session_start();
$user = $_SESSION['myuser'];
$conn=mysql_connect(.....) or die('server not found');
$db='mydb';
mysql_select_db($db) or die('.: database done exist :.');
$sel="delete from cart where cuser = '$user'";
$result=mysql_query($sel) or die('.: can\'t perform the query :.');
mysql_close();
?>
<script type="text/javascript">
window.location="basket.php";
</script>
</body>
</html>

since i dont know yet how to remove an item individually..i erase them
all.
Add ID field to DB table and set it to auto_increment , now each time
you add new record to the DB table, it will have unique id. To delete
just pass ID to the remove script via GET or POST: remove.php?id=1 ,
query should look like this: delete from cart where cuser = '$user'
AND id = '$id'

You may want to look into this: http://www.tizag.com/phpT/postget.php

Don't forget to check all user input before using it with DB table.

~Maiku

Apr 16 '07 #2
ok so mean i need to convert it to a form..like this:
<form name='reg' method='get' action='rem.php'>
while (..){
// display the data here...
}
</form>

on this line instead of a link ill change to a submit button:
echo '<font face="Verdana" size="1"><input type="submit"...>

then my rem.php contains:
<html>
<head>
</head>
<body>
<?php
session_start();
$user = $_SESSION['myuser'];
$id=$_GET['id'];
..
..
..

am i getting it right? sorry im new to this so im making things as
detailed as possible. tnx;-)

Apr 16 '07 #3
On Apr 16, 12:25 pm, "shotokan99" <soft_devj...@yahoo.comwrote:
ok so mean i need to convert it to a form..like this:
<form name='reg' method='get' action='rem.php'>
while (..){
// display the data here...
}
</form>

on this line instead of a link ill change to a submit button:
echo '<font face="Verdana" size="1"><input type="submit"...>

then my rem.php contains:
<html>
<head>
</head>
<body>
<?php
session_start();
$user = $_SESSION['myuser'];
$id=$_GET['id'];
.
.
.

am i getting it right? sorry im new to this so im making things as
detailed as possible. tnx;-)
Could work but I think something like:
session_start();
$user = $_SESSION['myuser'];

while (..){
echo $nameOfItem + ' (<a href="remove.php&amp;id='+$idOfItem
+'">Delelte</a>) '; //You can wrap it into a table, this is just
example.
}

if isset($_GET["id"]) {
$remId = mysql_real_escape_string($_GET["id"]); //Or whatever user
input check/prepare function you want to use.
$query = "delete from cart where cuser = '$user';
AND id = '$remId' ";
mysql_query($query);
}

I don't want to discourage you, but have you tried checking free php
cart scripts? At worst case you will find good programming approaches/
examples there.

~Maiku

Apr 16 '07 #4
actually ur right. there are lots of free scripts done by
professionals out there and some of them are free. however, how will i
learn if ill settle to free scripts? i know my approach or style of
programming is very elementary but i think that's the way it is if
you're still new ;-)

yes this is the hard way but i believe this way will benefit me alot
later..

just want to clarify...this line:
(<a href="remove.php&amp;id='+$idOfItem +'">Delelte</a>)

is it really "&amp;" or "&"

Apr 17 '07 #5
On Apr 17, 8:45 am, shotokan99 <soft_devj...@yahoo.comwrote:
actually ur right. there are lots of free scripts done by
professionals out there and some of them are free. however, how will i
learn if ill settle to free scripts? i know my approach or style of
programming is very elementary but i think that's the way it is if
you're still new ;-)

yes this is the hard way but i believe this way will benefit me alot
later..
Use your own style. But learning other styles is a plus.
That's an advice from my martial art gurus. ;)
just want to clarify...this line:
(<a href="remove.php&id='+$idOfItem +'">Delelte</a>)

is it really "&" or "&"
CMIIW
The separator between url and query string variables is a
'?' (question mark).
But the separator among variables in a query string is a
'&' (ampersand).
Unless you do something with arg_separator.output in your php.ini

Apr 17 '07 #6
is it really "&" or "&"
My bad it should be:
(<a href="remove.php?id='+$idOfItem +'">Delelte</a>)

Here's a good tutorial: http://www.keithjbrown.co.uk/vworks/php/php_p2.php

Apr 17 '07 #7
Message-ID: <11**********************@y80g2000hsf.googlegroups .comfrom
Maiku Mori contained the following:
>
>is it really "&" or "&"
My bad it should be:
(<a href="remove.php?id='+$idOfItem +'">Delelte</a>)
The concatenation operator in PHP is a dot.

Were you perhaps thinking of Javascript?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Apr 17 '07 #8
@bocah..
so ur into what discipline of martial arts? learning other style is
good? perhaps having an overview is ok but dnt u think getting stuck
in ur own style for mastery is better? hahaha..anyhow that's off topic
beyond php stuff.

ok let me try it with a '?' question mark..

Apr 18 '07 #9
i know u guys are well-verse in php, for the sake of expanding my
knowledge. in ur experience(s) which u think is better, asp or php?

Apr 18 '07 #10
shotokan99 wrote:
i know u guys are well-verse in php, for the sake of expanding my
knowledge. in ur experience(s) which u think is better, asp or php?
Speaking in plain English.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 18 '07 #11
@jerry
what do you when u said speaking in plain english? ur referring to
what?

Apr 18 '07 #12
shotokan99 wrote:
@jerry
what do you when u said speaking in plain english? ur referring to
what?
Maybe you should learn how to spell and speak in plain English.

Do you see anyone else here talking crap like you are?

==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 18 '07 #13
On Apr 18, 12:16 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
shotokan99 wrote:
@jerry
what do you when u said speaking in plain english? ur referring to
what?

Maybe you should learn how to spell and speak in plain English.

Do you see anyone else here talking crap like you are?
Jerry, is posting abusively in Usenet groups part of your job
description, or are you just a miserable crank in your spare time?

Granted, his post is a little grating on the eyes (and I don't like
what's happening to the English language myself, frankly), but his
meaning was clear and he was asking a valid question.

To answer shotokan's question, IMHO any technology that isn't platform-
specific is more appealing. PHP doesn't restrict you to Apache or
IIS, it'll run on both (as well as others.) This has advantages in
portability, as well as your job prospects once you become
proficient. What happens when you leave one job that's an IIS shop to
go to another that runs Apache?

Granted, the IIS shop is more than likely drinking the MS Kool-Aid and
is using ASP.NET, but maybe they're not.

Apr 18 '07 #14
Evil Otto wrote:
On Apr 18, 12:16 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>shotokan99 wrote:
>>@jerry
what do you when u said speaking in plain english? ur referring to
what?
Maybe you should learn how to spell and speak in plain English.

Do you see anyone else here talking crap like you are?

Jerry, is posting abusively in Usenet groups part of your job
description, or are you just a miserable crank in your spare time?

Granted, his post is a little grating on the eyes (and I don't like
what's happening to the English language myself, frankly), but his
meaning was clear and he was asking a valid question.

To answer shotokan's question, IMHO any technology that isn't platform-
specific is more appealing. PHP doesn't restrict you to Apache or
IIS, it'll run on both (as well as others.) This has advantages in
portability, as well as your job prospects once you become
proficient. What happens when you leave one job that's an IIS shop to
go to another that runs Apache?

Granted, the IIS shop is more than likely drinking the MS Kool-Aid and
is using ASP.NET, but maybe they're not.
If he's going to post in international newsgroups, he should learn to
use proper language.

If for no other reason that English is no the native language for the
entire worlds, and many non-native English speakers have trouble
understanding it.

But it's also obvious he's a teeny-bopper, unused to proper
communications. It never hurts to learn.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 18 '07 #15
Evil Otto wrote:
....
Jerry, is posting abusively in Usenet groups part of your job
description, or are you just a miserable crank in your spare time?
Those international readers, who do not speak English well,
appreciate greatly Jerry's indirect request to write simple and easy
language.

?:s dir. to spe. gr shd be av. :)
Apr 18 '07 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ralph Freshour | last post by:
I'm not sure the follow multiple table query is the right way to do what I need to do although it seems to be working: $php_SQL = "SELECT * ". "FROM basics, personal, photos ". "WHERE...
9
by: NRGY | last post by:
Hi. I need help with a filtering function that I can't get to whatever I try. I have this output that I need to filter: <tr> <td class="box_content" align="center">3,259</td> <td...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
3
by: Mark Lees | last post by:
Just installed 2003 and the help file sucks because it tries to connect to Microsoft Online Help which takes too long. When I run Access and I'm not connected to the internet, it seems to connect...
2
by: John Baker | last post by:
I find it highly annoying that MS Access tries to go online when I want to look at the help files. Is there a way to configure it so it just looks at my local helpfiles when I hit F1?
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
8
by: Elliot M. Rodriguez | last post by:
I am having a heckuva time debugging this, or determining why my page is behaving this way. I have a search form, that when completed, returns a datagrid. When the user selects a row (normal...
5
by: Tia Carr | last post by:
When I press F1 on Date, all I get is two paragraphs on the Date date type. The intellisense feature indicates there are a few dozen methods and properties associated with Date. Where can I get...
3
by: kaipiroz | last post by:
Hi all, I have this js array dynamically generated by the server and converted to JSON format: var punti = and I need to catch the online status for every user but : for (prop in punti) {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.