Hi there,

Although I wouldn't consider myself a noob, I am still learning about the many facets of PHP. I have encountered a need to write an if statement that will generate an error if the specific criteria are not met.

Here's the deal...
There are four fields that a user can type in a specific quantity.
Those four fields are named:

wild_mush_qty
spinric_rav_qty
cava_qty
tort_qty

When completed, the if statement needs to add up those fields to make sure it is in an increment of four.

So basically you can fill out the four fields listed above with any value, as long as the total between the four is evenly divided by four. Not sure if that makes it easier to understand, but yeah, that's what I'm looking to do.

Can anyone help me to get this started?
My deep appreciation and thanks for the help.

Recommended Answers

All 3 Replies

What is the error ? I am still confused about what you want and what is the problem. Do you mean something like this ?

<?php
if(isset($_POST['submit'])) {
	$total = $_POST['field1']+$_POST['field2']+$_POST['field3']+$_POST['field4'];
	if($total % 4 == 0) {
		echo "$total Divisible by 4..";
	} else {
		echo "$total Not divisible by 4..";
	}
}
?>
<html>
<body>
	<form method='post' action='test.php'>
Field1:	<input type='text' name='field1'><br />
Field2:	<input type='text' name='field2'><br />
Field3:	<input type='text' name='field3'><br />
Field4:	<input type='text' name='field4'><br />
<input type='submit' name='submit' value='submit'>
	</form>
</body>
</html>

:-/ If this is not what you mean, you need to describe your question in detail with relevant code.

Just wanted to say thank you.
Sorry I wasn't so specific, but what you listed above is exactly what I needed to get started.
I wasn't getting an error message...I was trying to generate one. Sorry I wasn't more specific. But thanks!!! :-)

Cool ! Good luck :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.