vendredi 27 février 2015

For loop in nested form not posting all values

I am using nested forms and my inner form works right. But my outer form is not posting the value



productname0


which is not having any value(as it is hidden). And it is not posting



productname1


(which is visible).

This is my code:



<script>
function formsubmit(name)
{
document.forms[name].submit();
}
</script>
<form name="newpurchase" action="productpurchasesql.php" method="POST">
<?php
for($i=0;$i<2;$i++)
{
?>
<tr <?php if($i==0){ ?> style="display:none;" <?php } ?>><td>PRODUCT NAME:</td><td>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" name="productselection<?php echo $i; ?>">
<select name="productname<?php echo $i; ?>" onchange="formsubmit('productselection<?php echo $i; ?>');">
<option value="-">Select</option>
<?php
$con=mysql_connect("localhost","root","");
mysql_selectdb("computer",$con);
$sql="select productname from product order by productname";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
if($prvs!=$row['productname'])
{
?>
<option value="<?php echo $row['productname']; ?>" <?php if(isset($_POST['productname'.$i]) && strcmp($_POST['productname'.$i],$row['productname'])==0){ ?> selected="selected" <?php } ?>><?php echo $row['productname']; ?></option>
<?php
}
$prvs=$row['productname'];
}
?>
</select>
</td></tr>
<tr <?php if($i==0){ ?> style="display:none;" <?php } ?>><td>COMPANY NAME:</td><td>
<?php
if(isset($_POST['productname'.$i]) && $_POST['productname'.$i]!=="-")
{
?>
<select name="companyname<?php echo $i; ?>">
<?php
$productnamereceived=$_POST['productname'.$i];
$sql="select companyname from product where productname='$productnamereceived' order by companyname";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
?>
<option value="<?php echo $row['companyname']; ?>"><?php echo $row['companyname']; ?></option>
<?php
}
}
?>
</td></tr>
<tr <?php if($i==0){ ?> style="display:none;" <?php } ?>><td>INVOICE NO:</td><td><input type="text" name="invoiceno<?php echo $i; ?>" <?php if(isset($_POST['productname'.$i]) && isset($_POST['invoiceno'.$i])){ ?> value="<?php echo $_POST['invoiceno'.$i]; ?>" <?php } ?>></td></tr>
</form>
<?php
}
?>
</table> <br>
<center><input type="submit" value="Add Entry" onclick="formsubmit('newpurchase');">
</form>


Note: I'm working this code for ie6.



What should I do to make my code post the value of "productname1" in "productpurchasesql.php"



If possible suggest me better code for ie6.

Thank you.


Aucun commentaire:

Enregistrer un commentaire