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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.