hlep on PHP error

joejoe BeginnerLink Clerk
Please have a look on my code below: I got a error as

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/GCO01/public_html/1/index.php on line 16"

mu database named "test", how can I fix it?

<form action=index.php method=post>
<table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
<tr><td colspan=2 align=center bgcolor=#123dd4>LOGIN</td></tr>
<tr><td align=right>Username: </td><td><input type=text name=user size=15></td></tr>
<tr><td align=right>Password: </td><td><input type=password name=pass size=15></td></tr>
<tr><td align=center colspan=2><input type=submit value=Login></td></tr>
</table>
</form>

<?php
if ($_POST[user] && $_POST[pass]) {
$user_data = mysql_fetch_array(mysql_query("select id, username, password from users where username='$_POST[user]' and password='$_POST[pass]'"));
if ($user_data[id] > 0) {
setcookie ("user", md5($user_data[username]));
setcookie ("pass", md5($user_data[password]));
header("Location: index.php");
} else { $login_error= true; }
}
?>

<?php
if ($login_error == true) { ?>
<table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
<tr><td align=center bgcolor=#123dd4>LOGIN ERROR</td></tr>
<tr><td align=center><b>Invalid Username and/or Password</b><br><br><a href=index.php>Back</a></td></tr>
</table>
<?
} elseif ($_COOKIE[user] == md5($username) && $_COOKIE[pass] == md5($password)) { ?>
<table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
<tr><td align=center bgcolor=#123dd4>SECURE AREA</td></tr>
<tr><td>You have successfully logged in.<br><br>
Encrypted Username: <b><?= $_COOKIE[user] ?></b><br>
Encrypted Password: <b><?= $_COOKIE[pass] ?></b><br>
</td></tr>
</table>
<?
}
?>

Comments

  • james.ukjames.uk Junior Member Shared Hoster
    can you please post lines 1 - 30 for us, thanks
    A psychopath with dyslexia
  • joejoe Beginner Link Clerk
    That all what I had in my file, what's missing?
  • gillygilly Junior Member Shared Hoster
    Try this
    [PHP]
    <form action=index.php method=post>
    <table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
    <tr><td colspan=2 align=center bgcolor=#123dd4>LOGIN</td></tr>
    <tr><td align=right>Username: </td><td><input type=text name=user size=15></td></tr>
    <tr><td align=right>Password: </td><td><input type=password name=pass size=15></td></tr>
    <tr><td align=center colspan=2><input type=submit value=Login></td></tr>
    </table>
    </form>

    <?php
    if ($_POST[user] && $_POST[pass]) {
    $query = mysql_query("select id, username, password from users where username='$_POST[user]' and password='$_POST[pass]'")
    $user_data = mysql_fetch_array($query);
    if ($user_data[id] > 0) {
    setcookie ("user", md5($user_data[username]));
    setcookie ("pass", md5($user_data[password]));
    header("Location: index.php");
    } else { $login_error= true; }
    }
    ?>

    <?php
    if ($login_error == true) { ?>
    <table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
    <tr><td align=center bgcolor=#123dd4>LOGIN ERROR</td></tr>
    <tr><td align=center><b>Invalid Username and/or Password</b><br><br><a href=index.php>Back</a></td></tr>
    </table>
    <?
    } elseif ($_COOKIE[user] == md5($username) && $_COOKIE[pass] == md5($password)) { ?>
    <table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
    <tr><td align=center bgcolor=#123dd4>SECURE AREA</td></tr>
    <tr><td>You have successfully logged in.<br><br>
    Encrypted Username: <b><?= $_COOKIE[user] ?></b><br>
    Encrypted Password: <b><?= $_COOKIE[pass] ?></b><br>
    </td></tr>
    </table>
    <?
    }
    ?>[/PHP]
  • james.ukjames.uk Junior Member Shared Hoster
    i hate my work computer its so new and shiney, BUT I CANT DO FECK ALT! yea sorry.. back to work.
    A psychopath with dyslexia
Sign In or Register to comment.