|
Posted by Greg on 10/19/05 23:08
I'm not new to the login script, however I'm trying to do it with Classes,
which I am new too. Two pages involved, login.php and clsLoginForm.php .
The login.php file submits to itself, it the values are not defined the form
is shown, (this part works fine) and if the values are found checks the
database for a match and redirects.
The login.php file looks like this:
<?
$username = $_POST['username'];
$userpassword = $_POST['userpassword'];
if (empty($_POST['username']) || empty($_POST['userpassword'])){
$showform = &new LoginForm;
echo $showform->showform();
}
else
{
$login = &new LoginForm;
$login->username = "$username";
$login->userpassword = "$userpassword";
$login->userlogin();
}
?>
The clsLoginForm.php class looks like this. The problem is with my sql
context look for //THIS IS WHERE THE PROBLEM IS below:
<?
class LoginForm{
function showform()
{
// define the submission to self
$self = $_SERVER['PHP_SELF'];
// Create the Form
$form = "<form method=\"post\" action=\"$self\">\n";
$form .= "<table width=\"100%\" align=\"center\">\n";
$form .= "<tr>\n";
$form .= "<td width=\"30%\" align=\"right\">Username:</td><td
align=\"left\"><input type=\"text\" value=\"" . $_POST['username'] . "\"
name=\"username\"></td>\n";
$form .= "</tr>\n";
$form .= "<tr>\n";
$form .= "<td align=\"right\">Password:</td><td align=\"left\"><input
type=\"password\" value=\"" . $_POST['userpassword'] . "\"
name=\"userpassword\"></td>\n";
$form .= "</tr>\n";
$form .= "<tr>\n";
$form .= "<td></td><td align=\"left\"><input type=\"submit\"
class=\"formsubmit\" name=\"submit\" value=\"Login\"></td>\n";
$form .= "</tr>\n";
$form .= "</table>\n";
$form .= "</form>\n";
// Show the form
return $form;
}
function userlogin()
{
include $_SERVER['DOCUMENT_ROOT'] . "/includes/dbconnect_admin.php";
/* These are unused variables. I was trying it this way when it wasn't
working before
$username = $this->username;
$userpassword = $this->userpassword;*/
// THIS IS WHERE THE PROBLEM IS
$sql = "SELECT * FROM users WHERE username=$this->username AND
password=$this->userpassword";
// END PROBLEM
$results = mysql_query($sql);
$dbdata = mysql_fetch_array($results);
$row = mysql_num_rows($results);
if ($row == NULL){
$showform = &new LoginForm;
echo $showform->showform();
}
else
{
session_start();
$_SESSION['fname'] = $dbdata["fname"];
$_SESSION['lname'] = $dbdata["lname"];
header ("Location: http://www.somesite.com");
exit();
}
}
}
?>
The Error i'm getting is:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in /home/berrock/public_html/classes/clsLogin_Form.php on line 42
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource in /home/berrock/public_html/classes/clsLogin_Form.php on line 43
Any ideas? Thanks in advance for any help.
Greg
[Back to original message]
|