smti Posted March 30, 2008 Share Posted March 30, 2008 Hello I've created an IF statement to verify whether or not information has been entered into two form fields -- if there is no data, the function (is supposed to) output an error. (By jumping to error function). If there is data in the boxes, then the script is to call a second function which checks the entered data against a MYSQL database. The Problem: Regardless of whether or not data is entered the main function (validatelogin() ) calls the error function. Here is my code: function validatelogin(){ if ('$_POST[username]=="" ' || '$_POST[password]=="" '){ loginerror(); } else { verifylogin(); } } function verifylogin(){ // Retrieve all data from proper user (If one exists) $result = mysql_query("SELECT * FROM users where username='$_POST[username]' and password='$_POST[password]'"); // Extract data and store. $row = mysql_fetch_array( $result ); // Print out the contents of the entry echo "Username: ".$row['username']; echo "Password: ".$row['password']; echo "Access: ".$row ['accesslevel']; echo "<br>"; $query = mysql_query ("SELECT * FROM users where username='$_POST[username]' and password='$_POST[password]'"); $number=mysql_num_rows($query); echo "Total records in table= ". $number; echo "<br>"; if ($number==1) echo "Record found!"; else echo "No Record Found!"; } function loginerror(){ echo "Oh no! There has been an error!"; } Any help would be greatly appreciated! Thanks, smti Link to comment https://forums.phpfreaks.com/topic/98560-if-statement/ Share on other sites More sharing options...
don117 Posted March 30, 2008 Share Posted March 30, 2008 if ('$_POST[username]=="" ' || '$_POST[password]=="" '){ This should read if (($_POST['username'] == "") || ($_POST['password'] == "")) { What you did was essentialy just compare two non-empty strings that are always true. Link to comment https://forums.phpfreaks.com/topic/98560-if-statement/#findComment-504430 Share on other sites More sharing options...
smti Posted March 30, 2008 Author Share Posted March 30, 2008 Oh geez. Thanks for your help! - smti Link to comment https://forums.phpfreaks.com/topic/98560-if-statement/#findComment-504435 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.