NETSYNC Posted November 5, 2011 Share Posted November 5, 2011 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 More sharing options...
NETSYNC Posted November 5, 2011 Author Share Posted November 5, 2011 I figured it out actually. I simply made the second section and ELSE of the top if instead of two seperate. So if the field is empty it does not even check the database at all. Link to comment https://forums.phpfreaks.com/topic/250520-echo-shows-on-when-it-shouldnt/#findComment-1285310 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.