Forum Moderators: coopster

Message Too Old, No Replies

Post method keeps sending same data

Post method keeps sending same data

         

bono

3:08 pm on Jun 13, 2005 (gmt 0)

10+ Year Member



Hi I need some help with some code..

im tryin to send some data from a form to a php script ( a basket) but im not sure whats going wrong.....

here my input script..:

{

$view_db = '<tr><td><img src=images/test-small-image.jpg></td><td class=bold>'.$row['productname'].'</td><input type=hidden name=id value='.$row['productID'].'>';
$view_db .= '<td align=center>'.$row['size'].'</td>';
$view_db .= '<td align=center class=bold>'.$row['price'].'</td><input type=hidden name=price value='.$row['price'].'>';
$view_db .= '<td align=center class=bold><input type=image src=images/addtocartup.jpg border=0 name=add></td></tr>';
echo $view_db;

}

and my output script

<?PHP
$prodID=$_POST['id'];
$qty="1";
$price=$_POST['price'];
print $prodID;
print $qty;
print $price;

?>

I think it isnt working because the variables have the same name.. but i dont have a clue how to change this... sorry for being a noob

dreamcatcher

3:37 pm on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bono, welcome to Webmaster World. :)

mmm....whats the problem exactly? Nothing displaying? Error message? Also, whats your form action? Is that the problem?

bono

4:27 pm on Jun 13, 2005 (gmt 0)

10+ Year Member



Hi,

problem is that when i clcik add to basket it always sends the last item on the list not the first..

so say i click "pink widget £25" and theres "blue widget £35" on the next row it always posts the bleu widget at £35 :-s

cant work out how to stop it

coopster

9:12 pm on Jun 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It seems all your input values here are of type "hidden" so whatever is in the last one in the form is likely going to be returned in your variable. You have to make your products an array and also make it something that will be returned -- input type of say, submit or checkbox, etc.

PHP and HTML FAQ:
[php.net...]