Jump to content

Php Login error


pagemaker

Recommended Posts

Hi everyone. I am looking for some help with this Php login script I keep getting the following error. Can some please tell me how to fix this.

 

Fatal error: Call to undefined function login() in /home/thedewbe/public_html/loginphp/checklogin.php  on line 32

below is line 31, 32 and 33 of my code

}
if (login($_POST['username'],$_POST['password']) == TRUE)
{

 

I just can not see what is wrong here.

any help would be great.. Thank you

Link to comment
https://forums.phpfreaks.com/topic/197313-php-login-error/
Share on other sites

Here is the whole code:

 

?php
$host="localhost"; // Host name
$username="mydomain"; // Mysql username
$password="mypassword"; // Mysql password
$db_name="mydb"; // Database name
$tbl_name="mytable"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "/login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:/login_success.php");
}
else {
echo "Wrong Username or Password";
}
if (login($_POST['username'],$_POST['password']) == TRUE)
{
// User logged in. store username in session variables
session_register("username");
$_SESSION['username'] = $_POST['username'];
}
?>

Hope this helps

Link to comment
https://forums.phpfreaks.com/topic/197313-php-login-error/#findComment-1035629
Share on other sites

The problem is, you're calling a function  -- login() -- that hasn't been defined anywhere in this code.

 

there would have to be something on your page that would say something like:

 

function login($username, $password) 
{
$sql="SELECT * FROM $tbl_name WHERE username='$username'"
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result))
    {
if ($password==$row['password'])
        {
return true;
         }
     }
}

 

where you're defining the login function and checking to see if those conditions are both met. Since username is already determined with the sql (it's finding the record that matches the username) you only have to see if the password then matches.

 

P.s. watch out when you're parsing user inputted data ... you need to clean it before sending it to the database or you're wide open to sql injection.

 

 

Link to comment
https://forums.phpfreaks.com/topic/197313-php-login-error/#findComment-1035633
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.