login

login error

Page 1 of 1

8 Replies - 792 Views - Last Post: 07 March 2010 - 07:21 PM Rate Topic: -----

#1 aru1  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 5
  • Joined: 21-September 09

login

Posted 06 March 2010 - 11:51 PM

i created a login page when iam login the database connection is successfull but the hedderfile function is not working this is my Code

if($_POST['submit'])
	{
	$username=$_POST['user'];
	$password=$_POST['pass'];

	$result = mysql_query("SELECT * FROM register WHERE UserName='$username' AND Password='$password'");
	echo $result;
	$rowCheck = mysql_num_rows($result); 
	if($rowCheck > 0){ 
	while($row = mysql_fetch_array($result)){ 
	
	}
	echo "Login Is Success";
	header("location:Success.php");
}
else { 

    print 'Incorrect login name or password. Please try again.'; 
  } 
  }



Can You Help Me ?

This post has been edited by JackOfAllTrades: 07 March 2010 - 07:49 AM
Reason for edit:: Added code tags. PLEASE!!! [code]...PUT YOUR CODE IN HERE...[/code]


Is This A Good Question/Topic? 0
  • +

Replies To: login

#2 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: login

Posted 06 March 2010 - 11:59 PM

header needs t be used before anything is output to the browser. Remove the echo(s) before it and it should work fine =)
Was This Post Helpful? 2
  • +
  • -

#3 KingCuddles  Icon User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: login

Posted 07 March 2010 - 02:23 AM

As JBrace1990 said the header function cannot be called after any output.

For more information on the header function check out the PHP manual

Also in future please use code tags to display your code, just remove the spaces:

[ code ] CODE HERE [ /code ]
Was This Post Helpful? 0
  • +
  • -

#4 aru1  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 5
  • Joined: 21-September 09

Re: login

Posted 07 March 2010 - 10:09 AM

Thanks for Your Advice But The Problem Still Exist

this is the error

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Login\Login.php:8) in C:\xampp\htdocs\mylogin\Login.php on line 122

what can i do
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,221
  • Joined: 23-August 08

Re: login

Posted 07 March 2010 - 10:22 AM

Read and understand this
Was This Post Helpful? 1
  • +
  • -

#6 KingCuddles  Icon User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: login

Posted 07 March 2010 - 11:23 AM

JackOfAllTrades, JBrace1990 and myself have all answered the question for you, there should be no problems now.

This post has been edited by KingCuddles: 07 March 2010 - 11:24 AM

Was This Post Helpful? 0
  • +
  • -

#7 dr_h0us3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 07-March 10

Re: login

Posted 07 March 2010 - 02:54 PM

Hi,
try:
<?php
//connection database
$connection = mysql_connect("localhost", "$userdb", "$senhadb")or die (mysql_error());
// select the database.
$db = mysql_select_db("test",$connection)or die (mysql_error());
// searching bd
mysql_query("SELECT * FROM users WHERE login = '$login' And senha = md5('$senha') ")or die (mysql_error());
$lines = mysql_affected_rows();
if($lines == 1)
{
$_SESSION['user'] = $login;
header("Location: index.php");
}
else
{
header("Location: login.php");
}
?>

Was This Post Helpful? 0
  • +
  • -

#8 KingCuddles  Icon User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: login

Posted 07 March 2010 - 03:28 PM

View Postdr_h0us3, on 07 March 2010 - 01:54 PM, said:

Hi,
try:
<?php
//connection database
$connection = mysql_connect("localhost", "$userdb", "$senhadb")or die (mysql_error());
// select the database.
$db = mysql_select_db("test",$connection)or die (mysql_error());
// searching bd
mysql_query("SELECT * FROM users WHERE login = '$login' And senha = md5('$senha') ")or die (mysql_error());
$lines = mysql_affected_rows();
if($lines == 1)
{
$_SESSION['user'] = $login;
header("Location: index.php");
}
else
{
header("Location: login.php");
}
?>


While your code rectifies the problem of output before the header, you should try to help people understand what they have done wrong, rather than just giving them code.
Was This Post Helpful? 0
  • +
  • -

#9 X@MPP  Icon User is offline

  • 僕わ馬鹿ですね?
  • member icon

Reputation: 36
  • View blog
  • Posts: 1,014
  • Joined: 20-February 09

Re: login

Posted 07 March 2010 - 07:21 PM

View PostKingCuddles, on 07 March 2010 - 09:28 PM, said:

View Postdr_h0us3, on 07 March 2010 - 01:54 PM, said:

Hi,
try:
<?php
//connection database
$connection = mysql_connect("localhost", "$userdb", "$senhadb")or die (mysql_error());
// select the database.
$db = mysql_select_db("test",$connection)or die (mysql_error());
// searching bd
mysql_query("SELECT * FROM users WHERE login = '$login' And senha = md5('$senha') ")or die (mysql_error());
$lines = mysql_affected_rows();
if($lines == 1)
{
$_SESSION['user'] = $login;
header("Location: index.php");
}
else
{
header("Location: login.php");
}
?>


While your code rectifies the problem of output before the header, you should try to help people understand what they have done wrong, rather than just giving them code.

Hes new give him a break ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1