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
 
Last edited:

dqhendricks

New Member
This means that you are outputting something to the page before you are setting the header. You must not output anything (including whitespace), before setting a header. Sometimes your code will appear to have no whitespace before your opening <?php tag, even though it really does if you are using an editor not meant for this type of code editing.

Hope that makes sense. If you would like to learn more about PHP development, here is a link to a good PHP centric web development blog: http://www.spotlesswebdesign.com/blog.php
 

jalicia18

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

You can use this one
//header('location:http://www.obtp.net/login_success.php');
echo "<script>window.location='http://www.obtp.net/login_success.php'</script>";
 
Top