Jump to content

[SOLVED] Issue with posting empty form variables


moracca

Recommended Posts

ok, so the basic html is this (extraneous info taken out):

<form name="add" action="<?=$PHP_SELF?>" method="post">

<?php

while $row=mysql_fetch_array($result){

<<yadda yadda>>

echo "<input type=\"text\" name=\"qty[" . $row['itemid'] . "]\">";

}

?>

<input type="submit" name="add" value="add">

</form>

 

Ok, so say there are 3 results, so therefore 3 qty inputs.  When it gets posted back to the form, all 3 inputs get posted, even if they are empty.  For example:

 

session_start();

if ($_POST['add']){

echo "number of postqty items=" . count($_POST['qty']) . "<br>";

foreach ($_POST['qty'] as $id => $quant){

echo "value of this ids quant: " . $_POST['qty'][$id] . "<br>";

echo "id=$id<br>";

echo "quant=$quant<br>";

$_SESSION['cart'][$id] += $quant;

echo "cartid=" . $_SESSION['cart'][$id];

echo "ONCE<br>";

 

}

}

will return:

number of postqty items=3

value of this ids quant: 2

id=1

quant=2

cartid=2ONCE

value of this ids quant:

id=2

quant=

cartid=0ONCE

value of this ids quant:

id=3

quant=

cartid=0ONCE

 

 

I want to only change the session variables if they input a quantity in the form.  Any ideas?  This is bothering me.  Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.