Hey I was working through a PHP tutorial for building a php registration and login script. I was able to get the registration script to work fine but I'm having trouble with the PHP login script I keep getting the following error when I test the form:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /public_html/login/login.php on line 23
Parse error: syntax error, unexpected $end in /public_html/login/memberspage.php on line 29
Here is the login.php file minus the actual db login info for obvious reasons:
<?php
//Database Information
$dbhost = "localhost";
$dbname = "your database name";
$dbuser = "username";
$dbpass = "yourpass";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = "select where username='$username' and password='$password'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
include "login.html";
} else {
$_SESSION['username'] = "$username";
include "memberspage.php";
}
?>
Here is the memberspage.php file:
<?
// members page
session_start();
if ( empty( $username ) ) {
print "Please login below!";
include 'login.html';
} else {
// you can use regular html coding below the ?>
// and before the <?
?>
<html>
<head>
<title>MEMBERS ONLY</title>
</head>
<body>
Your Members Page....
</body>
</html>
<?
I went through other tutorials and tried altering the offending lines but I wasn't able to get it to work right.
Also, I'm looking to add a logout script to the memberspage.php file. I want the user to be able to click a simple href link that will log them out. How do you attach a logout php file to a normal link?
Any help would be greatly appreciated. Thanks!