Forum Moderators: coopster
i tried a simple login functionality. my requirement is ,if the login usermane and password is correct , display the username in the next page(user's page). The username cannot be displayed the next page.
This code works fine in my local machine with PHP Version 5.1.4, but dosent work in my webserver with PHP Version 4.3.4. The username is displayed in the 'userlogin1.php' page when working in local machine.. but not in webserver.
can anyone please sort out the problem for me...
code:
<?php
session_start();
include("conn.php");
// checking the login
$strDB=mysql_connect($strServer,$strUser,$strPwd);
if(!$strDB) die("Cannot connect to Server");
$database=mysql_select_db("$strDatabase",$strDB);
if(isset($_POST['username']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$query = "Select * From security Where Username = ('$username') And password = ('$password')";
$result = mysql_query($query);
if (mysql_num_rows($result)==1)
{
$_SESSION['uname']=$username;
header('Location: userlogin1.php');
}
else
{
$msg="Invalid user";
}
}
mysql_close($strDB);
?>
userlogin.php // this is the page where the username has to be dispalyed
<?php
session_start();
if(!isset($_SESSION['uname']))
{
header("Location: index.php");
}
echo($_SESSION['uname'])?>
Try removing the parenthesis
<<<
$query = "Select * From security Where Username = '$username' And password = '$password'";
>>>
The way you are using Headers down below the script very top calls for Output Buffering OB
to be turned on in your PHP.ini
Two options either you decide on the side of your OB
Or you just type: On
Depending on traffic and what OB will be performing your site might be just a tad slower.
$username = [url=http://us2.php.net/manual/en/function.mysql-real-escape-string.php]mysql_real_escape_string[/url]($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$query = "Select * From security Where Username = '$username' And password = '$password'";
;)