1

UPDATE: changed some sql queries and now it transfers to the control panel. Although it shows these error.

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/lewism/public_html/admin/rent/login_success.php:10) in /home/lewism/public_html/admin/rent/login_success.php on line 74

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/lewism/public_html/admin/rent/login_success.php:10) in /home/lewism/public_html/admin/rent/login_success.php on line 74

Warning: Cannot modify header information - headers already sent by (output started at /home/lewism/public_html/admin/rent/login_success.php:10) in /home/lewism/public_html/admin/rent/login_success.php on line 76

~Hey guys,

Just using a login script from phpeasysteps.com and it provides the following error when I try to login, Any suggestions

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lewism/public_html/admin/rent/checklogin.php on line 27 Wrong Username or Password

Below is the code for the checklogin.php

<?php
$host="localhost"; // Host name 
$username="lewism_lewis"; // Mysql username 
$password="teamgreen"; // Mysql password 
$db_name="lewism_car"; // Database name 
$tbl_name="Customers"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];

// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

Thanks guys,

Ais

1
  • Obligatory "escape your input". Use mysql_real_escape_string. Commented Mar 16, 2012 at 23:14

2 Answers 2

1

Try doing

$result = mysql_query($sql) or die(mysql_error());
                           ^^^^^^^^^^^^^^^^^^^^^^--- add this

Since $result is not a valid handle for mysql_num_rows, find out why the query failed.

Beyond that, I suggest you NOT grab code samples for PHP. most of them, including the stuff you've posted are hideously out of date or outright wrong. At least this one uses mysql_real_escape_string, but it's still using stripslashes and session_register.

Both are deprecated, and the magic_quotes stuff that stripslashes "undoes" is actually outright removed now in the latest PHP version.

Sign up to request clarification or add additional context in comments.

3 Comments

OK I've fixed this by changing the sql select statement to the correct variables.
Unfortunately it now displays this Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/lewism/public_html/admin/rent/checklogin.php:2) in /home/lewism/public_html/admin/rent/checklogin.php on line 32 Warning: Cannot modify header information - headers already sent by (output started at /home/lewism/public_html/admin/rent/checklogin.php:2) in /home/lewism/public_html/admin/rent/checklogin.php on line 34
look for that error message on this site. it's been asked/answered about a gazillion times.
0

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

source

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.