|
|
|
|
Thread title: Error with classes. |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
03-19-2006, 07:59 PM
|
#1
|
Status: Member
Join date: Jul 2005
Location: Massachusetts, US
Expertise:
Software:
Posts: 428
|
Error with classes.
Originally Posted by My Website
Warning: Missing argument 1 for Login::login() in C:\Server\htdocs\Games\Game1\includes\functions.ph p on line 103
Warning: Missing argument 2 for Login::login() in C:\Server\htdocs\Games\Game1\includes\functions.ph p on line 103
Warning: Missing argument 3 for Login::login() in C:\Server\htdocs\Games\Game1\includes\functions.ph p on line 103
|
Fix: Needed to make the class and function/object different names.
Those are the errors I get when I use this code: (I commented line 103.)
PHP Code:
<?
if(isset($_POST['login']))
{
include("includes/header.php");
class Login
{
function all_forms($email,$password)
{
if(!empty($email) && !empty($password))
{
$login1 = "yes";
}
elseif(empty($email))
{
$login1 = "no";
?>
You have not entered your e-mail.
<?
include("includes/footer.php");
die();
}
elseif(empty($password))
{
$login1 = "no";
?>
You have not entered your password.
<?
include("includes/footer.php");
die();
}
return $login1;
}
function valid_email($email)
{
if(preg_match("/^[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}$/", $email))
{
$login2 = "yes";
}
else
{
$login2 = "no";
?>
The e-mail you entered is not a valid e-mail address.
<?
include("includes/footer.php");
die();
}
return $login2;
}
function check($email,$password)
{
$query1 = $Sql->act("escape", $Sql->act("query", "SELECT * FROM `users` WHERE `email` = '" . $email . "' AND password = '" . $password . "'"));
if($Sql->act("num_rows", $query1) > "0")
{
$login3 = "yes";
}
else
{
$login3 = "no";
?>
The e-mail or password you supplied are inaccurate.
<?
include("includes/footer.php");
die();
}
return $login3;
}
function login($email, $password, $remember)//line 103
{
$this->all_forms($email,$password);
$this->valid_email($email);
$this->check($email,$password);
if($login1 == "yes" && $login2 == "yes" && $login3 == "yes")
{
$sql1 = $Sql->act("fetch_array", $query1);
if(isset($remember))
{
setCookie("id", md5($sql1['id']), time()+30*24*60*60);
}
$_SESSION['id'] = md5($sql1['id']);
?>
You have been logged in.
<?
include("includes/footer.php");
die();
}
}
}
$Login = new Login;
}
?>
PHP Code:
<?
if(isset($_POST['login']))
{
$Login->login($_POST['txt_Email'], $_POST['txt_Password'], $_POST['txt_Remember']);
}
?>
Apparently it won't load the stuff inbetween the parentheses.
New Problem:
PHP Code:
<?
function all_forms($email,$password)
{
if(!empty($email) && !empty($password))
{
return 1;
}
elseif(empty($email))
{
return 0;
$msg .= "You have not entered your e-mail.";
}
elseif(empty($password))
{
return 0;
$msg .= "You have not entered your password.";
}
}
function valid_email($email)
{
if(preg_match("/^[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}$/", $email))
{
return 2;
}
else
{
return 0;
$msg .= "The e-mail you entered is not a valid e-mail address.";
}
}
function check($email,$password)
{
$query1 = mysql_query("SELECT * FROM `users` WHERE `email` = '" . $email . "' AND `password` = '" . $password . "'");
if(mysql_num_rows($query1) > "0")
{
return 3;
}
else
{
return 0;
$msg .= "The e-mail or password you supplied are inaccurate.";
}
}
function checking($email, $password, $remember)
{
$login = all_forms($email,$password);
$login = valid_email($email);
$login = check($email,$password);
if($login == 3)
{
$query1 = mysql_query("SELECT * FROM `users` WHERE `email` = '" . $email . "' AND `password` = '" . $password . "'");
$sql1 = mysql_fetch_array($query1);
if(isset($remember))
{
setCookie("id", md5($sql1['id']), time()+30*24*60*60, "/");
}
$_SESSION['id'] = md5($sql1['id']);
$msg .= "You have been logged in. " . $sql1['id'];
}
else
{
$msg .= "You didn't pass inspection. Please try again.";
}
return $msg;
}
?>
The cookie and session are not being set. The session actually gets set, but for 1 page only. The cookie not at all.
|
|
03-19-2006, 08:37 PM
|
#2
|
Status: I love this place
Join date: Apr 2005
Location:
Expertise:
Software:
Posts: 721
|
Originally Posted by xZaft
Those are the errors I get when I use this code: (I commented line 103.)
PHP Code:
<?
if(isset($_POST['login']))
{
include("includes/header.php");
class Login
{
function all_forms($email,$password)
{
if(!empty($email) && !empty($password))
{
$login1 = "yes";
}
elseif(empty($email))
{
$login1 = "no";
?>
You have not entered your e-mail.
<?
include("includes/footer.php");
die();
}
elseif(empty($password))
{
$login1 = "no";
?>
You have not entered your password.
<?
include("includes/footer.php");
die();
}
return $login1;
}
function valid_email($email)
{
if(preg_match("/^[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}$/", $email))
{
$login2 = "yes";
}
else
{
$login2 = "no";
?>
The e-mail you entered is not a valid e-mail address.
<?
include("includes/footer.php");
die();
}
return $login2;
}
function check($email,$password)
{
$query1 = $Sql->act("escape", $Sql->act("query", "SELECT * FROM `users` WHERE `email` = '" . $email . "' AND password = '" . $password . "'"));
if($Sql->act("num_rows", $query1) > "0")
{
$login3 = "yes";
}
else
{
$login3 = "no";
?>
The e-mail or password you supplied are inaccurate.
<?
include("includes/footer.php");
die();
}
return $login3;
}
function login($email, $password, $remember)//line 103
{
$this->all_forms($email,$password);
$this->valid_email($email);
$this->check($email,$password);
if($login1 == "yes" && $login2 == "yes" && $login3 == "yes")
{
$sql1 = $Sql->act("fetch_array", $query1);
if(isset($remember))
{
setCookie("id", md5($sql1['id']), time()+30*24*60*60);
}
$_SESSION['id'] = md5($sql1['id']);
?>
You have been logged in.
<?
include("includes/footer.php");
die();
}
}
}
$Login = new Login;
}
?>
PHP Code:
<?
if(isset($_POST['login']))
{
$Login->login($_POST['txt_Email'], $_POST['txt_Password'], $_POST['txt_Remember']);
}
?>
Apparently it won't load the stuff inbetween the parentheses.
|
Looks as though the $_POST variables you are trying to fill the login() function with are empty.
You could just set defaults in the function definition so that if the variables entered are empty you have the flexibility to spit out your own error messages, instead of PHP's.
PHP Code:
function login($email = '', $password = '', $remember = '0' /*I'm guessing remember is a boolean entity? */)//line 103
{
$this->all_forms($email,$password);
$this->valid_email($email);
$this->check($email,$password);
if($login1 == "yes" && $login2 == "yes" && $login3 == "yes")
{
$sql1 = $Sql->act("fetch_array", $query1);
if(isset($remember))
{
setCookie("id", md5($sql1['id']), time()+30*24*60*60);
}
$_SESSION['id'] = md5($sql1['id']);
?>
You have been logged in.
<?
include("includes/footer.php");
die();
}
}
|
|
03-19-2006, 08:40 PM
|
#3
|
Status: design rockstar
Join date: Jan 2005
Location: guelph, ontario
Expertise:
Software:
Posts: 2,246
|
$_POST['txt_$thing'] isn't retuning any value. what's the code for the form look like? instead of trying to call the login method, print_r($_POST) and see if it spits any values back.
secondly, did you declare a new instance of login before trying to call the method? this code is too exclusive to tell.
|
|
03-20-2006, 01:44 AM
|
#4
|
Status: I love this place
Join date: Apr 2005
Location:
Expertise:
Software:
Posts: 721
|
I would also recommend using pseudo type references to the class, as then you can avoid globalizing:
Instead of:
$login->do_login();
It would be:
login::do_login();
|
|
03-20-2006, 10:05 AM
|
#5
|
Status: I love this place
Join date: Mar 2005
Location:
Expertise:
Software:
Posts: 640
|
I'd also like to note that your class shouldnt be between an if statement, that kind of defeats the purpose of using classes. Instead create your class in a seperate file (or outside of the if statement) and initiate it between the if statement.
|
|
03-20-2006, 10:23 PM
|
#6
|
Status: Member
Join date: Jul 2005
Location: Massachusetts, US
Expertise:
Software:
Posts: 428
|
Sorry guys, we did something about it. The class name couldn't be the same as the function/objects.
Cole, that would defeat the purpose because then no one could get it no matter what . I needed it so it could show me the errors from PHP.
Derek, I did do that, and it did return the values correctly.
Cole Post 2, I would do that if I didn't sack the use of a class.
Sysblnk, I did that so I could work on other parts of the site, since it would error other things while I waited for answers, and forgot to take out.
Ok, now to edit the post with the new error.
|
|
03-20-2006, 11:15 PM
|
#7
|
Status: design rockstar
Join date: Jan 2005
Location: guelph, ontario
Expertise:
Software:
Posts: 2,246
|
have you used session_start() on the page you want the session info to carry over to?
like, if login.php sets the sessons and forwards the user to index.php, index.php needs session_start(); declared. you have to declare that everywhere you want to use session info.
as for the cookie, the code for setting the cookie is right, but maybe the problem lies in $remeber. if $remeber is empty the code wn't execute.
|
|
03-21-2006, 01:44 AM
|
#8
|
Status: Member
Join date: Jul 2005
Location: Massachusetts, US
Expertise:
Software:
Posts: 428
|
Ok, sorry guys, figured this out too. Apparently Firefox isn't too great with cookies. I deleted some before, and refues were left, so it broke. I fixed it again. I had to delete the cookies.
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|