Jump to content

IF Statement


smti

Recommended Posts

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

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.