Jump to content
Larry Ullman's Book Forums

Recommended Posts

My form loads ok. login.php

 

everything works like it should EXCEPT that when I submit the form with no password value I get the followoing error:

 

Notice: Undefined variable: p in C:\EasyPHP\www\basicMySql\includes\login_functions.inc.php on line 41

 

But if i fill in a value, even a false one, the code works fine. 

 

could it be something to do with my isset()/empty() function?

Link to comment
Share on other sites

function redirect_user($page = 'index.php') {

//define URL URL id http:// + host name + current directory

$url = 'http://' .$_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF']);

 

//remove any trailing slashes

$url = rtrim($url, '/\\');

//add the page:

$url .= '/' .$page; //add slashes that u removed

 

//redirect the user

header("Location:$url");

exit(); //quit script

} //end of redirect_user() 

 

/* This function validates the form data(the email address and password). If both are present, the database is queried. 

The function requires a database connection.The function returns an array of information, including: a TRUE/FALSE variable indicating

success - an array of either errors or the database result

 */

 

 function check_login($dbc, $email = '', $pass = '') {

$errors = array(); // initialize error array

if(empty($email)) { //validate the email and password

$errors[] = 'You forgot to enter your email address';

} else {

$e = mysqli_real_escape_string($dbc, trim($email));

}

if(empty($pass)) {

$erros[] = 'You forgot to enter your password';

} else {

$p = mysqli_real_escape_string($dbc, trim($pass));

}

 

if (empty($errors)) { //if no erros occurred, run the databse query

// Retrieve the user_id and first_name for that email/password combination:

$q = "SELECT user_id, first_name FROM users WHERE email='$e' AND pass=SHA1('$p')";

$r = @mysqli_query($dbc, $q);

//now check the results of the query:

if(mysqli_num_rows($r) == 1) {

//fetch the record

$row = mysqli_fetch_array($r, MYSQLI_ASSOC);

return array(true, $row); //return true and the record

} else { //Not a match!

$errors[] = 'The email and password entered do not matCH ThOse oN fiLe';

}

} //End of empty($errors) IF

 

//Return False and the errors:

return array(false, $errors);

 } //End of check_login() function
Link to comment
Share on other sites

kwandoa, you really need to read the forum guidelines before you post again. You are consistently leaving out the most critical information, which makes trying to help impossible. Read them now, and abide them in the future.

Link to comment
Share on other sites

 Share

×
×
  • Create New...