Jump to content

Echo shows on when it shouldnt


NETSYNC

Recommended Posts

Hey all.  I have a simple code for verifying some data.  I have two echos from if statements.  The first is if the text input is empty echo: HELLO.  The second is if text input data is not found in database echo: NOPE.

 

Now in the following code the second one works fine.  But the problem is if I leave the field empty BOTH echos show.  So if I leave the input empty instead of saying "HELLO"  it says, "HELLONOPE".

 

Yet the second one works fine and display only "NOPE"

 

The other thing is if I switch the two echos to die instead, they work fine.

 

if (isset($_POST['submit'])) { 

// if form has been submitted
// makes sure they filled it in
	if(!$_POST['id']) {

echo "HELLO";

	}
	// checks it against the database


	$check = mysql_query("SELECT * FROM emp WHERE id = '".$_POST['id']."'")or die(mysql_error());


//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {

echo "NOPE";
				}

else 
{ 

//if login good then redirect them to the members area 
$id = $_POST['id'];
header("Location: somepage.php?id=$id"); }
} 

else {	 

// they are not logged in



}

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">  
<input type="text" name="id" maxlength="40">  <input type="submit" name="submit" value="Login"> </form> 

 

What am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/250520-echo-shows-on-when-it-shouldnt/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.