Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

151 users online



login scipt

login scipt

Currently viewing this thread: 1 (0 members and 1 guests)


james182

james182

Neverside Newbie
Status: Offline!

login scipt

here is my login script i can't get it to work properly ...
you type user and pass and goes to blank it should go to success.php if correct or bad.php if no success.

PHP:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
    <title>Untitled</title>
</head>

<body>
<form action="login.php">
<table width="200" cellpadding="0" cellspacing="4" border="0" class="loginbox">
    <tr>
        <td width="100" valign="top" align="left">
            <span class="title">Username:</span><br>
        </td>
        <td width="100" valign="top" align="left">
            <INPUT TYPE='TEXT' NAME='username' VALUE='' size='15'><br>
        </td>
    </tr>
    <tr>
        <td width="100" valign="top" align="left">
            <span class="title">Password:</span><br>
        </td>
        <td width="100" valign="top" align="left">
            <INPUT TYPE='password' NAME='password' VALUE='' size='15'><br>
        </td>
    </tr>
    <tr>
        <td width="100" valign="top" align="left">
            <br>
        </td>
        <td width="100" valign="top" align="right">
            <input type="submit" name="login" value="login"><br>
        </td>
    </tr>
</table>
</form>
<?
include("connect.php");

$username $_POST["username"];
$password $_POST["password"];

$result MYSQL_QUERY("SELECT * FROM login WHERE username='$username'and password='$password'")
   or die (
"Name and password not found or not matched");

$worked mysql_fetch_array($result);

$username $worked[username];
$password $worked[password];
$email $worked[email];

if(
$worked)
   echo 
"<a href='admin.php'>enter</a>"
?>
</body>
</html>

BigToach

BigToach

Neversidian
Status: Offline!

you would need it to actually somehow send it to good.php or bad.php. All you have it do right now is have a link to admin.php if you do get in successfully.

I know that you are trying to learn php, but you really need to ask a question and not just ask someone to fix your scripts. First of all, thats not what we are here to do. If you have a specific question about how to do a specific task then ask away. Every once in a while if you cant find an error or something thats great. But the past like 5 posts by you have been similar to this.

this isnt just because this is against the general policies in SS, you also dont learn when someone else solves your problems. The only real way to learn the language and know it well, is to fix your own mistakes.

so try and figure out why this script isnt working, if you cant figure it out post reasons that you think might be the problem and we will see if we can direct you in a better direction to solve your problem.

___________________

Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

johnzer

johnzer

Neverside Newbie
Status: Offline!

You should use a type when using the form attribute.

tcbil

tcbil

I hate Customer Services!
Status: Offline!

Should they not be something about the submit at the begining of your php?

PHP:

<?
if($submit)
{
YOUR PHP CODE
}
?>

___________________

PHP Freak Wannabe!

tcbil

tcbil

I hate Customer Services!
Status: Offline!

tried the following but still hitting a wall:

login.php

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>
<form action="inc/login.inc.php">
<table width="200" cellpadding="0" cellspacing="4" border="0" class="loginbox">
<tr>
<td width="100" valign="top" align="left">
<span class="title">Username:</span><br>
</td>
<td width="100" valign="top" align="left">
<INPUT TYPE='TEXT' NAME='username' VALUE='' size='15'><br>
</td>
</tr>
<tr>
<td width="100" valign="top" align="left">
<span class="title">Password:</span><br>
</td>
<td width="100" valign="top" align="left">
<INPUT TYPE='password' NAME='password' VALUE='' size='15'><br>
</td>
</tr>
<tr>
<td width="100" valign="top" align="left">
<br>
</td>
<td width="100" valign="top" align="right">
<input type="submit" name="submit" value="submit"><br>
</td>
</tr>
</table>
</form>
</body>
</html>

login.inc.php

PHP:

<?
if($submit)
{
mysql_connect("localhost","user","pass"); 
mysql_select_db("db"); 

$username $_POST["username"];
$password $_POST["password"];

$result MYSQL_QUERY("SELECT * FROM _login WHERE username='$username'and password='$password'")
   or die (
"Name and password not found or not matched");

$worked mysql_fetch_array($result);

$username $worked[username];
$password $worked[password];

if(
$worked)
    
Header ("Location: URL");
}
?>

it then tells me this:

Name and password not found or not matched

will carry on trying and see what i come up with

___________________

PHP Freak Wannabe!

Last edited by tcbil, August 30th, 2005 02:14 PM (Edited 1 times)

gregor

gregor

Neverside Newbie
Status: Offline!

Try this .... And note what I have changed:

- you should really make a point of cleaning any user submitted data
- note that the from now has a 'method' and that it submits to itself

Please ASK QUESTIONS about this if you have them.

PHP:

<?php

if(isset($sumbit)) {

$authenticatedUser false;

mysql_connect("localhost","user","pass");
mysql_select_db("db");
    
    
//clean up form fields
    
if (get_magic_quotes_gpc()) {
        
$username stripslashes($_POST['username'];
        
$password stripslashes($_POST['password'];
    }    
    
$username trim(mysql_real_escape_string($username));
    
$password trim(mysql_real_escape_string($password));
    
    
$sql "SELECT username, password FROM _login WHERE username = '$username' AND password = '$password'";
    
    if (!
$queryResult mysql_query($sql)) {
        die(
"Authentication query failed to execute.");
    }
    
$userCount mysql_num_rows($queryResult);
    
// if your query has retrieved more than one username/password match -- not a good thing
    
if ($userCount 1) {
        die(
"Not cool ...");
    
//else if there are no rows -- incorrect uname/pass provided    
    
} elseif ($userCount == 0) {
        
$errorMessage "Invalid username or password. Please try again";
    } else {
        
//if there is only 1 row -- success!
        
if ($usercount == 1) {
            
$authenticatedUser true;
        }
        
//handle any other possibility
        
$authenticatedUser false;
    }
    
    if (
$authenticatedUser == true) {
        
header('Location: successpage.php');
    }
}
//end if form submitted        
?>

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>

<body>
<?php
if ($errorMessage) {
echo $errorMessage;
}
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<table width="200" cellpadding="0" cellspacing="4" border="0" class="loginbox">
<tr>
<td width="100" valign="top" align="left">
<span class="title">Username:</span><br>
</td>
<td width="100" valign="top" align="left">
<INPUT TYPE='TEXT' NAME='username' VALUE='' size='15'><br>
</td>
</tr>
<tr>
<td width="100" valign="top" align="left">
<span class="title">Password:</span><br>
</td>
<td width="100" valign="top" align="left">
<INPUT TYPE='password' NAME='password' VALUE='' size='15'><br>
</td>
</tr>
<tr>
<td width="100" valign="top" align="left">
<br>
</td>
<td width="100" valign="top" align="right">
<input type="submit" name="submit" value="submit"><br>
</td>
</tr>
</table>
</form>
</body>
</html>

___________________

sixminutes.ca

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0101 seconds.