pagemaker Posted April 2, 2010 Share Posted April 2, 2010 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 More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 The error states pretty clearly. The login() function does not exist. Have you defined it somewhere? Link to comment https://forums.phpfreaks.com/topic/197313-php-login-error/#findComment-1035623 Share on other sites More sharing options...
pagemaker Posted April 2, 2010 Author Share Posted April 2, 2010 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 More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 Yep. No login() function defined there. Your also using the long deprecated session_register. Link to comment https://forums.phpfreaks.com/topic/197313-php-login-error/#findComment-1035630 Share on other sites More sharing options...
pagemaker Posted April 2, 2010 Author Share Posted April 2, 2010 This code is on the destination page if loging is successful <? session_start(); if(!session_is_registered(username)){ header("location:main_login.php"); } ?> <html> <body> Login Successful </body> If this is all wrong then I am screwed I guess.. Link to comment https://forums.phpfreaks.com/topic/197313-php-login-error/#findComment-1035632 Share on other sites More sharing options...
Jax2 Posted April 2, 2010 Share Posted April 2, 2010 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 More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 If this is all wrong then I am screwed I guess.. The code should be re-written. As I said, session_register is deprecated. Your also calling a non-existent function - login(). Link to comment https://forums.phpfreaks.com/topic/197313-php-login-error/#findComment-1035636 Share on other sites More sharing options...
pagemaker Posted April 2, 2010 Author Share Posted April 2, 2010 I see thanks for the help I will try and re-write the cod better and se how it goes. I am still really new to this stuff. I know what I want just cant get there is all. Link to comment https://forums.phpfreaks.com/topic/197313-php-login-error/#findComment-1035641 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.