Log in script error

There are two files
1]main_login.php [It works fine.]
2]checklogin.php [It gives error.]

This is code for main_login.php
[php]

Member Login
Username
Password
[/php]

This is the code for checklogin.php
[php]

<?php session_start(); $con=mysql_connect("localhost","root","root"); if(!$con) die('Couldnt connect:'.mysql_error()); $db=mysql_select_db("my_db",$con); if(!$db) die('Could not select Database:'.mysql_error()); $username=$_POST['username']; $password=$_POST['password']; //to protect mysql injection $username=stripslashes($username); $password=stripslashes($password); $username=mysql_real_escape_string($username); $password=mysql_real_escape_string($password); $sql="select count(*) from members where username='$username' and password='$password'"; $result=mysql_query($sql); if(!$result) die('Query Failed'); $row=mysql_fetch_row($result); $count=$row[0]; if($count==1) { $_SESSION['username']=$username; header("location:login_sucess.php"); } else { echo "Wrong Username or Password"; } mysql_close(); ?>

[/php]
Checklogin.php shows following errors:
1] Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\easy\checklogin.php:2) in C:\xampp\htdocs\easy\checklogin.php on line 3

2] Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\easy\checklogin.php:2) in C:\xampp\htdocs\easy\checklogin.php on line 3

3] Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\easy\checklogin.php:2) in C:\xampp\htdocs\easy\checklogin.php on line 29

Is the PHP code above any HTML? If it isn’t, place it right at the top of the file and try again :slight_smile:

I tried. But it still does not work…

FYI, it’s not specifically HTML code - if that opening PHP tag isn’t the very first character in the file, it will break. Any whitespace or newline characters etc will send the headers and render those functions useless. Make sure the <?php is at the very beginning of the file (and isn’t being included in another file that has output anything).

Thank you.
The problem has been solved.

Sponsor our Newsletter | Privacy Policy | Terms of Service