Hello all, I have a site with login system, when I run it on my local sever it worked perfectly ok, but when uploaded it was not taking me to member page as on my local server.

Please can anybody help me with this.

The codes are below.

myconfig.php

<?php
$con=mysql_connect("localhost","leomconn_leom","happiness100");
if(!$con)
{
die("Database connection failed: ".mysql_error());
}

//selecting the database and inserting into the database
mysql_select_db("leomconn_leomdatabase",$con);
?>

registered.php

<?php 
if (isset($_POST['Submit']))
{
	include("myconfig.php");
	$username = $_POST["username"];
	$password = $_POST["password"];
	
	
	$check = mysql_query("SELECT * FROM registered WHERE username = '$username'");
	if(mysql_num_rows($check)==0)
	{
		$ins = mysql_query("INSERT INTO registered(username, password) VALUES('$username', '$password')");
		echo "<br/>";
		echo "<font color=#000000  size=+2> Entered Succefully</font>"; echo "<br/>";
		echo "<br/>";
				}
		else
		{
		echo "<font color=#000000 size=+2> Username already exist</font><br/>";
		}
}
?>

index.php

<?php

if(isset($_POST['Submit']))
{
	include("myconfig.php");
	$username=$_POST["username"];
	$password=$_POST["password"];
	$check=mysql_query("select * from registered where username='$username' AND password='$password'");
	if(mysql_num_rows($check)==0)
	echo "<font color=#0000FF>Make Payment to be activated </font><br/>";
	
	//creatinga a sersion and header that redirects it to the page called secret.php
	else
	{
	$_SESSION[xyz]=$username;
	// the secret.php page is the page the user goes after he logs in succefully
	header("Location:member.php");
	
	}
}

?>

I will really appreciate if anybody can help me out.

thanks all

Treasurepet

Member Avatar for diafol

have you changed the DB login details?

have you changed the DB login details?

Yes I have done that

Member Avatar for diafol

you seem to be missing braces.
Also enclose array keys in quotes.
Also set session_start() - you don't seem to have that so sessions shouldn't work.

if(mysql_num_rows($check)==0)  //SHOULD BE A { HERE
echo "<font color=#0000FF>Make Payment to be activated </font><br/>";

//creatinga a sersion and header that redirects it to the page called secret.php
//SHOULD BE A } HERE
else
{
$_SESSION[xyz]=$username; //MAKE THIS $_SESSION['xyz']
// the secret.php page is the page the user goes after he logs in succefully
header("Location:member.php");

}

Are you sure you got this to work on localhost?

you seem to be missing braces.
Also enclose array keys in quotes.
Also set session_start() - you don't seem to have that so sessions shouldn't work.

if(mysql_num_rows($check)==0)  //SHOULD BE A { HERE
echo "<font color=#0000FF>Make Payment to be activated </font><br/>";

//creatinga a sersion and header that redirects it to the page called secret.php
//SHOULD BE A } HERE
else
{
$_SESSION[xyz]=$username; //MAKE THIS $_SESSION['xyz']
// the secret.php page is the page the user goes after he logs in succefully
header("Location:member.php");

}

Are you sure you got this to work on localhost?

I have made the changes and it does not work, I also set session_start(), is running fine on my localhost...I don't really know the problem. I

I have made the changes and it does not work, I also set session_start(), is running fine on my localhost...I don't really know the problem. I

Hello all, can anybody help? I have tried all I could but still cannot redirect to member.php, instead this is the error am getting.

PLEASE HELP


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

Please I need somebody to help

Member Avatar for diafol

You can't use header() if you have output to the page (e.g. static html or php output like echo or any whitespace).

You can't use header() if you have output to the page (e.g. static html or php output like echo or any whitespace).

Thanks for your response, Please what do I do from here am a newbie, can you please help me with what to do again. thanks

Member Avatar for diafol

I've told you - you can't use header() if you've already outputted something to the page. Ensure that all (or most) your php is above the Doctype Declaration and that you don't echo anything before the header(). You can save stuff to be outputted in variables until you need to output them in the relevant area of the page itself.

I've told you - you can't use header() if you've already outputted something to the page. Ensure that all (or most) your php is above the Doctype Declaration and that you don't echo anything before the header(). You can save stuff to be outputted in variables until you need to output them in the relevant area of the page itself.

Thanks so much for your responses and advice, I have tried all I could, moved all I could but still getting the same thing, Please can you help me re-modified the code.


myconfig.php

<?php
$con=mysql_connect("localhost","leomconn_leom","happiness100");
if(!$con)
{
die("Database connection failed: ".mysql_error());
}

//selecting the database and inserting into the database
mysql_select_db("leomconn_leomdatabase",$con);
?>


registered.php
<?php
if (isset($_POST))
{
include("myconfig.php");
$username = $_POST["username"];
$password = $_POST["password"];


$check = mysql_query("SELECT * FROM registered WHERE username = '$username'");
if(mysql_num_rows($check)==0)
{
$ins = mysql_query("INSERT INTO registered(username, password) VALUES('$username', '$password')");
echo "<br/>";
echo "<font color=#000000 size=+2> Entered Succefully</font>"; echo "<br/>";
echo "<br/>";
}
else
{
echo "<font color=#000000 size=+2> Username already exist</font><br/>";
}
}
?>

index.php
<?php

if(isset($_POST))
{
include("myconfig.php");
$username=$_POST["username"];
$password=$_POST["password"];
$check=mysql_query("select * from registered where username='$username' AND password='$password'");
if(mysql_num_rows($check)==0)
echo "<font color=#0000FF>Make Payment to be activated </font><br/>";

//creatinga a sersion and header that redirects it to the page called secret.php
else
{
$_SESSION[xyz]=$username;
// the secret.php page is the page the user goes after he logs in succefully
header("Location:member.php");

}
}

?>

thanks all the while.

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

Please I need somebody to help

As ardav said you cannot do that but there is a workaround. Use ob_start. If you want to know why, someone did took a trouble of explaining here

You can try

echo "<meta http-equiv='refresh' content='0;url=http://localhost/project/'>";
for redirection instead of header if same issue exist.

Are you sure you are redirecting to the correct page as this information is conflicting:

// the secret.php page is the page the user goes after he logs in successfully
header("Location:member.php");

You say they are redirected to secret.php when logged in successfully but in your header location you are redirecting to member.php.

Just a thought

Are you sure you are redirecting to the correct page as this information is conflicting:

// the secret.php page is the page the user goes after he logs in successfully
header("Location:member.php");

You say they are redirected to secret.php when logged in successfully but in your header location you are redirecting to member.php.

Just a thought

Yes, am redirecting to correct page, the secret.php is just in comment, the page is actually member.php

Yes, am redirecting to correct page, the secret.php is just in comment, the page is actually member.php

I know the problem but the way to solution is what I don't know, where and where will I place my header is the problem.

Instead of

$check=mysql_query("select * from registered where username='$username' AND password='$password'");

Try:

$query = "select * from registered where username='$username' AND password='$password'";

$check = mysql_num_rows($query);

Instead of

$check=mysql_query("select * from registered where username='$username' AND password='$password'");

Try:

$query = "select * from registered where username='$username' AND password='$password'";

$check = mysql_num_rows($query);

Thanks all, I was able to fix the error after lots of troubleshooting using

ob_start() and ob_flush()

thanks

Thanks all, I was able to fix the error after lots of troubleshooting

Yeah that is right because you don't read the answers given here. IF only you have worked on my post quoted below, you could have saved yourself alot of pains

As ardav said you cannot do that but there is a workaround. Use ob_start. If you want to know why, someone did took a trouble of explaining here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.