my code is like this

if (isset(POST_[submit])){
......if (empty($name))
..........echo "name field is empty";

......else if(isset($_POST[submit])){
............$name = $_POST[name];
........query
........mysql_cuery($query,$conn)
}
}
if (isset(POST_[submit2])){
......if (empty($pet))
..........echo "pet field is empty";

......else if(isset($_POST[submit2])){
............$pet = $_POST[pet];
........query
........mysql_cuery($query,$conn)
}
}

As you can see I have two submit buttons submit1 and submit two.
When I submit with the first one and the text field is empty I expect to receive the echo like this:
name field is empty
but I get the result like this
name field is emptypet field is empty
My question is what is the reason for geting the two echos instead of one echo?

<?php
if(!($_POST))
{
?>
	<form method = "post" action = "<?php echo $_SERVER['PHP_SELF'];?>">
		<table width = "400" align = "center">
			<tr>
				<td align = "right">Name : &nbsp;</td>
				<td><input type = "text" name = "name" size = "30"></td>
			</tr>
			<tr>
				<td align = "right">Pet : &nbsp; </td>
				<td><input type = "text" name = "pet" size = "30"></td>
			</tr>
			<tr>
				<td></td>
				<td>
				<input type = "submit" name ="submit1" value = "SUBMIT ONE">
				<input type = "submit" name ="submit2" value = "SUBMIT TWO">
				</td>
			</tr>
		</table>
	<form>
<?php
}
else
{
	if(isset($_POST['submit1']))
	{
		if(empty($_POST['name']))
		{
			echo "Name field is empty!";
		}
		else
		{
			$name = $_POST['name'];
			//Your query here
		}
	}
	if(isset($_POST['submit2']))
	{
		if(empty($_POST['pet']))
		{
			echo "Pet field is empty!";
		}
		else
		{
			$pet = $_POST['pet'];
			//Your query here
		}
	}
}
?>
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.