943,551 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 549
  • PHP RSS
Aug 16th, 2009
0

simple shoping cart problem!

Expand Post »
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>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
karin21 is offline Offline
15 posts
since Jul 2009
Aug 16th, 2009
0

Re: simple shoping cart problem!

I'm not positive that this is the problem but it looks like the most likely culprit
Quote ...
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.
Reputation Points: 48
Solved Threads: 11
Posting Pro
tiger86 is offline Offline
540 posts
since Feb 2008
Aug 16th, 2009
0

Re: simple shoping cart problem!

what should i do? should i change that lines? please help im so confused
Reputation Points: 10
Solved Threads: 0
Newbie Poster
karin21 is offline Offline
15 posts
since Jul 2009
Aug 17th, 2009
0

Re: simple shoping cart problem!

Click to Expand / Collapse  Quote originally posted by karin21 ...
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
Quote ...
$selected
that is within your if statement.
Last edited by tiger86; Aug 17th, 2009 at 12:21 am. Reason: Needed to be more specific!
Reputation Points: 48
Solved Threads: 11
Posting Pro
tiger86 is offline Offline
540 posts
since Feb 2008
Aug 18th, 2009
0

Re: simple shoping cart problem!

ok thanks tiger86, i just need to know what should i do im very confused.. anyone 's help much more appriciated.. thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
karin21 is offline Offline
15 posts
since Jul 2009
Aug 18th, 2009
0

Re: simple shoping cart problem!

Click to Expand / Collapse  Quote originally posted by karin21 ...
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?
Reputation Points: 48
Solved Threads: 11
Posting Pro
tiger86 is offline Offline
540 posts
since Feb 2008
Aug 18th, 2009
0

Re: simple shoping cart problem!

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
karin21 is offline Offline
15 posts
since Jul 2009
Aug 19th, 2009
0

Re: simple shoping cart problem!

use LIST or Array of your products so you can manage the previous product information with next one.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Aug 19th, 2009
0

Re: simple shoping cart problem!

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..!!?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
karin21 is offline Offline
15 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Need help with script
Next Thread in PHP Forum Timeline: issues with isset and $_GET





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC