|
|
Posted by HawkEye on 10/21/05 00:45
Greg wrote:
> 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
>
>
OK, no expert but lets see if I can help.
First, if you echo out the $sql what does it give you ? My first
susspicion is that it is not putting the values in that you think it is
hence the invalid sql messages.
Second, although it may be a typo in this message your include statement
doesn't look correct. It needs quotes and / or brackets IIRC (at least that
is how I normally use it) - include('connect.php');
If you have already checked these items then, let me know and when I get
time on Monday I'll create the files in work and see if I can sort it.
--
Regards
Neil
Registered Linux User 324599
"I think the surest sign that there is intelligent life out there in the
universe is that none of it has tried to contact us." - Calvin & Hobbes
Navigation:
[Reply to this message]
|