0

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

Edited by peter_budo: Keep It Clear - Do use code tags when posting any code

6
Contributors
17
Replies
18
Views
5 Years
Discussion Span
Last Post by Stefano Mtangoo
0

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?

0

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

Edited by Treasurepet: n/a

0

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

0

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

0

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

0

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.

0

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.

0

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

0

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

0

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

0

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.

0

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);
0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.