I got this code from dev cough.. Devarticles cough. It all works fine except I get this warning message:
Warning: Unable to jump to row 0 on MySQL result index 2 in c:\inetpub\wwwroot\login.php on line 11
quite new to php so not sure whats causing it, but Im real sure one of you good people will enlighten me [img]images/smilies/yawnb.gif[/img]
Heres the codePHP Code:<?PHP
$db = mysql_connect('localhost', 'Ant_the_mus', 'pass') or die("Couldn't connect to the database." );
mysql_select_db('Jokes') or die("Couldn't select the database" );
// Add slashes to the username, and make a md5 checksum of the password.
$_POST['user'] = addslashes($_POST['user']);
$_POST['pass'] = md5($_POST['pass']);
$result = mysql_query("SELECT userId FROM users WHERE userPass='$_POST[pass]' AND userName='$_POST[user]'" ) or die("Couldn't query the user-database." );
$num = mysql_result($result,0);
if (!$num) {
// When the query didn't return anything,
// display the login form.
echo "<h3>User Login</h3>
<form action='$_SERVER[PHP_SELF]' method='post'>
Username: <input type='text' name='user'><br>
Password: <input type='password' name='pass'><br><br>
<input type='submit' value='Login'>
</form>";
} else {
// Start the login session
session_start();
// We've already added slashes and MD5'd the password
$_SESSION['user'] = $_POST['user'];
$_SESSION['pass'] = $_POST['pass'];
// All output text below this line will be displayed
// to the users that are authenticated. Since no text
// has been output yet, you could also use redirect
// the user to the next page using the header() function.
// header('Location: page2.php');
echo "<h1>Congratulations</h1>";
echo "You're now logged in. Try visiting <a href="page2.php">Page 2</a>.";
}
?>








Bookmarks