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!😕

    $query = "select where username='$username' and password='$password'";
    

    have a close look at this line. select what?

      Your query's SQL is incomplete. It does not specify any columns to select nor the table from which they are to be selected:

      $query = "select where username='$username' and password='$password'";
      

      It should look something like:

      $query = "select username FROM table_name where username='$username' and password='$password'";
      // you may want to add some debugging until you get it working:
      $result = mysql_query($query);
      if(!$result)
      {
         die("Query failed ($query): " . mysql_error());
      }
      

        Thanks...a million! I don't know how I missed that. It took care of the problem with the login file. What about the error in the memberspage.php? I continue to get that error about line 29. There aren't 29 lines in memberspage.php. Oh...I really did finish it with <? ?>...I just accidentally left it out when I pasted the code in.

          froppo wrote:

          What about the error in the memberspage.php? I continue to get that error about line 29. There aren't 29 lines in memberspage.php.

          you have no closing bracket after your else statement

            WooHoo! It's working! Thanks a million guys!

              Write a Reply...