php login script help

kempachi

New Member
hey guys i need help with a little bit of code thats not working for my login script. im using php with mysql database. when i got to my website http://www.obtp.net/OBTP.htmland use my username and password for my login it comes up with the error saying

Warning: Cannot modify header information - headers already sent by (output started at /home/obtpnet/public_html/checklogin.php:9) in /home/obtpnet/public_html/checklogin.php on line 39


heres the php code im using for the checklogin.php
Code:
<?php
$host="localhost"; // Host name 
$username="obtpnet_obtp"; // Mysql username 
$password="evolution13"; // Mysql password 
$db_name="obtpnet_logintest"; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("localhost", "obtpnet_obtp", "evolution13")or die("cannot connect"); 
mysql_select_db("obtpnet_logintest")or die("cannot select DB");

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

// To protect MySQL injection (more detail about 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"
 
header('location:http://www.obtp.net/login_success.php');
}
else {
echo "Wrong Username or Password";
}

?>

if you guys know whats wrong please help
 

saviola

New Member
Check for white before or after <?php ?>, or for incorrect parentheses ... this kind of error coming from pre-visualization of data and subsequent attempt to redirect.
 
Top