simple shoping cart problem!

Reply

Join Date: Jul 2009
Posts: 15
Reputation: karin21 is an unknown quantity at this point 
Solved Threads: 0
karin21 karin21 is offline Offline
Newbie Poster

simple shoping cart problem!

 
0
  #1
Aug 16th, 2009
hi guys, i have working on this simple cart script,it goes like when selecting the product in combobox it will display the details of the
product into the textbox, i can display the details but my problem is when i select another product the previous
selected product was replaced.. what should i do to keep the selected first,second.. and so on product in the form? thanks

my script so far...



<html>
<head>
</head>

<body>

<form action="insert.php" method="post">

<?php
mysql_connect("localhost","root","");
mysql_select_db("Inventory") or die(mysql_error());


$sql="SELECT * FROM product order by id";
$query=mysql_query($sql);

echo "<select name='select' size='5'>";

while($row = mysql_fetch_array($query))

{
if ($_POST['select'] == $row['id']){
$pquan=$row['pquan'];
$sel=$row['sellprice'];
$pcode = $row['pcode'];
}
$selected = '';

   if (isset($_POST['select']) && strcmp($row['id'], $_POST['select']) == 0) 
    {
        
       $selected = ' selected="selected"';
    
    } 

printf ('<option value="%s"%s>%s</option>'. PHP_EOL, $row['pname'], $selected, $row['pname']);

}

echo "</optgroup>";

?>

</select>

<?php

 if ($_POST['submit'])
 {
  
$i = $_POST['count'];
       for ($x=0;$x<=$i;$x++)

 {
       
    
?>

<br>
<input type="text" name="textbox<?php echo $x; ?>" value="<?php echo htmlspecialchars(@$_POST['select']); ?>" size=5/>
<input type="text" name="textbox<?php echo $x; ?>" value="<?php echo $pcode ?>" size=5/>
<input type="text" name="textbox<?php echo $x; ?>" value="<?php echo $pquan ?>" size=5/>
<input type="text" name="textbox<?php echo $x; ?>" value="<?php echo $sel ?>" size=5/>
<input type="text" name="textbox<?php echo $x; ?>" size=5/>

<input type="submit" name="delete" value="Delete" /> 

<?php
    }
    $i++;
?>

<input type="hidden" name="count" value="<?php echo $i; ?>" />

<?php

 }
  else 
{

?>

<input type="hidden" name="count" value="0" />

<?php
  } 
  $i--
?>



<br>

<input type="submit" name="submit" value ="Add Text Box" />

</form>
</body>
</html>
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 469
Reputation: tiger86 is an unknown quantity at this point 
Solved Threads: 10
tiger86's Avatar
tiger86 tiger86 is offline Offline
Posting Pro in Training

Re: simple shoping cart problem!

 
0
  #2
Aug 16th, 2009
I'm not positive that this is the problem but it looks like the most likely culprit
if (isset($_POST['select']) && strcmp($row['id'], $_POST['select']) == 0)
{

$selected = ' selected="selected"';

}
I may be way off track here or I may be on the ball.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 15
Reputation: karin21 is an unknown quantity at this point 
Solved Threads: 0
karin21 karin21 is offline Offline
Newbie Poster

Re: simple shoping cart problem!

 
0
  #3
Aug 16th, 2009
what should i do? should i change that lines? please help im so confused
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 469
Reputation: tiger86 is an unknown quantity at this point 
Solved Threads: 10
tiger86's Avatar
tiger86 tiger86 is offline Offline
Posting Pro in Training

Re: simple shoping cart problem!

 
0
  #4
Aug 17th, 2009
Originally Posted by karin21 View Post
what should i do? should i change that lines? please help im so confused
I'm still a novice at PHP. I don't know if that line is the culprit but it would be the one I'd suspect. What I would do is comment it out temporarily and test the script. Don't be afraid of commenting out code if you are on a testing server since you can easily uncomment it. I wouldn't comment out code if I didn't know what the outcome was going to be and the code was live online.
**********
I am referring to the line
$selected
that is within your if statement.
Last edited by tiger86; Aug 17th, 2009 at 12:21 am. Reason: Needed to be more specific!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 15
Reputation: karin21 is an unknown quantity at this point 
Solved Threads: 0
karin21 karin21 is offline Offline
Newbie Poster

Re: simple shoping cart problem!

 
0
  #5
Aug 18th, 2009
ok thanks tiger86, i just need to know what should i do im very confused.. anyone 's help much more appriciated.. thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 469
Reputation: tiger86 is an unknown quantity at this point 
Solved Threads: 10
tiger86's Avatar
tiger86 tiger86 is offline Offline
Posting Pro in Training

Re: simple shoping cart problem!

 
0
  #6
Aug 18th, 2009
Originally Posted by karin21 View Post
ok thanks tiger86, i just need to know what should i do im very confused.. anyone 's help much more appriciated.. thanks
Karin may I suggest making it a multiple list, checkbox list, or a radio group instead of a drop down menu?
If I helped you I would appreciate it if you would give me some reputation.
Follow the new Social Network Planet Zuda On twitter. Planet Zuda should go live sometime in 2010.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 15
Reputation: karin21 is an unknown quantity at this point 
Solved Threads: 0
karin21 karin21 is offline Offline
Newbie Poster

Re: simple shoping cart problem!

 
0
  #7
Aug 18th, 2009
yes.maybe your right it should be more easier with check list or radio group but i started to make it in combobox and in my project im required to use combobox and textbox, is there any way to do it with that?
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 257
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: simple shoping cart problem!

 
0
  #8
Aug 19th, 2009
use LIST or Array of your products so you can manage the previous product information with next one.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 15
Reputation: karin21 is an unknown quantity at this point 
Solved Threads: 0
karin21 karin21 is offline Offline
Newbie Poster

Re: simple shoping cart problem!

 
0
  #9
Aug 19th, 2009
can you show me how to start with array i'am a newbie in php i tried to search for more tutorials from the net but im still confused in using array.. can you guide me please..!!?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 366 | Replies: 8
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC