froppo Posted July 19, 2007 Share Posted July 19, 2007 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! ??? Link to comment https://forums.phpfreaks.com/topic/60683-php-login-logout/ Share on other sites More sharing options...
totalllama Posted July 20, 2007 Share Posted July 20, 2007 Hi there, lets take a quick look at this then! In login.php the line $query = "select where username='$username' and password='$password'"; two problems, your not telling it which data to select and from which table it should read roughly $query = 'select * from users '."where username='$username' "." and password=password('$password')"; NOTE: that 'users' above is the name of my user table within my DB - yours could be different depending on how you set it up. ---- The second Parse error in memberspage.php looks like, the <? sitting on its own on the last line!! Link to comment https://forums.phpfreaks.com/topic/60683-php-login-logout/#findComment-303456 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.