misslois74
Programmer
im using an array of textboxes and put a validation on those textboxes in which if a user puts in a non-numeric value it should display an error message and would not proceed but it seems that my validation is not working bec. eventhough i've already entered a numeric value im still getting the error message and would not proceed on the next step...
here is the validation:
and here is the form:
thanks in advance.
here is the validation:
Code:
function validate_input()
{
global $errors;
if(!isset($_POST["qty"]) || trim($_POST["qty"]) == "")
{
$errors['qty1'] = "<font color='red' size='1'>*</font>";
$errors['qty2'] = "<font color='red' size='1'> * Choose at least one item</font><br>";
}
else if(!is_numeric(trim($_POST["qty"])))
{
$errors['qty3'] = "<font color='red' size='1'>*</font>";
$errors['qty4'] = "<font color='red' size='1'>Should be numeric value</font><br>";
}
else if(isFloat(trim($_POST["qty"])))
{
$errors['qty5'] = "<font color='red' size='1'>*</font>";
$errors['qty6'] = "<font color='red' size='1'>Should be integer value</font><br>";
}
}
and here is the form:
Code:
function display_form()
{
global $errors;
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Enter the quantity of the product you wish to order.</p><br />
<?php if(isset($errors['qty2']))
{
echo $errors['qty2'];
}
else if(isset($errors['qty4']))
{
echo $errors['qty4'];
}
else if(isset($errors['qty6']))
{
echo $errors['qty6'];
} ?>
<table width="650" border="0">
<tr>
<td width="135">Product Code</td>
<td width="153"><div align="center">Product Name</div></td>
<td width="103"><div align="center">Image</div></td>
<td width="67"><div align="center">Price</div></td>
<td width="56"><div align="center"> </div></td>
<td width="110"><div align="center">Quantity</div></td>
</tr>
</table>
<table width="655" border="0">
<?php
//print items from the catalog for selection
include "db_config.php";
$quer = "Select * from tbl_candle order by product_name";
$res = mysql_query($quer) or die(mysql_error());
//$nums
while($rows = mysql_fetch_array($res))
{ ?>
<tr><td width="176"><b><?php echo $rows[product_code]; ?></b></td>
<td width="173"><b><?php echo $rows[product_name]; ?></b></td>
<td width="125"><a href="<?php echo $rows[product_image]; ?>" onclick="window.open(this.href, 'child', 'height=200, width=250'); return false"><img src="<?php echo $rows[product_image]; ?>" width="74" height="69" title="CLICK TO ENLARGE"></a></td>
<td width="70"><b><?php echo $rows[product_price]; ?></b></td>
<td><center><input type="checkbox" name="order[]" value="<?php echo $rows[product_id]; ?>" onClick="myFunction('<?php echo $rows['product_id']. "qty"; ?>')"></center></td>
<td><center><input type="text" name="qty[<?php echo $rows['product_id']; ?>]" size="5" id="<?php echo $rows['product_id']."qty"; ?>" disabled></center></td><td><?php echo $errors['qty1']; echo $errors['qty3']; echo $errors['qty5']; ?></td></tr>
<?php }
} ?>
<tr>
<td colspan="5"><br />
<input type="hidden" value="additems" name="action" />
<center><input type="submit" name="submit" value="Add items to order" title="Click to Order"></center>
</td>
</tr>
</table>
</form>
thanks in advance.