Hello, I've been trying for 2 days to solve the following problem without success. As the experts on this board have never let me down yet I thought i'd ask for help (even though i don't like to admit defeat)
I have a page with a form consisting of a dropdown and two boxes. One of the text boxes is for product quantity and this is sent to the database as a 2 character string so quantity=3 would output 01, 02, 03 for example.
What I'd like to happen is when the user doesn't enter a value in either text box, a message saying - please enter the product / please enter the quantity / please neter the product and quantity is displayed depending on which text boxes have been completed.
Can anyone help? The data is posting to the database ok - it's just this simple : ) form validation bit that i can't figure out, Thanks.
<html>
<!-- The following Javascript function is called in the Body tag and clears the TextBox when the page is reloaded (after the data is sent to the database) -->
<script type="text/javascript" language="javascript">
function ClearTextboxes()
{
document.getElementById('product').value = '';
document.getElementById('quantity').value = '';
}
</script>
<body OnLoad="ClearTextboxes();">
<form name="form1" method="post" action="product.php">
<table border="1">
<tr>
<td width="120">
Select Type
</td>
<td>
<select name="product_type_id" value= "<?php echo $_POST['product_type_id'];?>" />
<OPTION VALUE="1">type1</OPTION>
<OPTION VALUE="2">type2</OPTION>
</select>
</td>
</tr>
<tr>
<td>
Product
</td>
<td>
<input type="text" name="product" id="product" value="<?php echo $_POST['product'];?>" />
</td>
</tr>
<tr>
<td>
Quantity
</td>
<td>
<input type="text" name="quantity" id="quantity" value="<?php echo $_POST['quantity'];?>" />
</td>
</tr>
</table>
<br />
<input type="submit" name="button" id="button" value="Submit" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
</body>
</html>
<?php
require_once('mysqli_connect.php');
$gt=trim($_POST['product_type_id']);
$gl=trim($_POST['product']);
$gq=trim($_POST['quantity']);
if (isset($_POST['submitted'])) {
if (!empty($_POST['product']) && !empty($_POST['quantity'])) {
for ($i=1; $i<$gq+1; $i++) {
if ($i<=9) {
$q1="INSERT INTO tbl_product (product_type_id,product,quantity) VALUES('$gt','$gl','0$i')";
$r = mysqli_query($dbc,$q1);
}else{
$q1="INSERT INTO tbl_product (product_type_id,product,quantity) VALUES('$gt','$gl','$i')";
$r = mysqli_query($dbc,$q1);
}
}
}
}
?>