PHP Programming > General PHP Help
why my code is not working properly
zakia:
--- PHP Code: ---<?php
if(isset($_POST['login']))
{
// Checking whether the Login form has been submitted
$err = array();
// Will hold our errors
if(!$_POST['username'] || !$_POST['password'])
$err[] = 'All the fields must be filled in!';
if(!count($err))
{
$_POST['username'] = mysql_real_escape_string($_POST['username']);
$_POST['password'] = mysql_real_escape_string($_POST['password']);
// Escaping all input data
$row = mysql_fetch_assoc(mysql_query("SELECT id,usr FROM tz_members WHERE usr='{$_POST['username']}' AND pass='".sha1($_POST['password'])."'"));
if($row['usr'])
{
header("Location:memberpage.php");
}
else $err[]='Wrong username and/or password!';
}
if($err){
$message=implode("<br/>",$err);
}
}
?>
--- End code ---
This my php code problem is that its not redirecting me to memberpage.php even i m doing correct entries according to my Datbase records. its still showing me Wrong username and/or password!';
plz help me where i m going wrong??????????????
--- Code: ---<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<title>Login</title>
</head>
<body>
<div id="container">
<div id="form">
<form action="#" method="post" class="format">
<h4>Login</h4>
<div class="box">
<?php
if(!empty($message))
{
echo '<div class="err">'.$message.'</div>';
}
?>
<label>Username:</label>
<input name="username" type="text" class="textbox" id="user">
<label>password:</label>
<input name="password" type="password" class="textbox" id="password"><br/>
<label><input name="rememberMe" type="checkbox" id="rememberMe" value="">Remeber Me
<span>|<a href="#"> Forgot Password</a></span></label>
<br/>
<input name="login" type="submit" value="Login" class="btn" id="login"><span><a href="reg.php">Sign Up</a></span>
</div>
</form>
</div> <!--Form-->
</div>
</body>
</html>
--- End code ---
dex2908:
Hi zakia,
You are having problem with your sql that's why the code is not working. It could be because you selected an invalid column from your table? I can't check that because i don't know your table's structure. However, from what i can see here, first of all you didn't connect to your database. To do that, you put the following code:
--- PHP Code: ---
$con = mysql_connect('localhost', 'root', 'put your db password here');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("put your database name here", $con);
--- End code ---
before you query from your database.
Next, your sql statement is incorrect:
"SELECT id,usr FROM tz_members WHERE usr='{$_POST['username']}' AND pass='".sha1($_POST['password'])."'"
Is there a reason why you usde curly braces {}? I haven't used that inside a statement before. Try change that to the following:
"SELECT id,usr FROM tz_members WHERE usr='".$_POST['username']."' AND pass='".sha1($_POST['password'])."'"
It should work..... let me know how it goes. Goood luck!
Regards,
developer.dex2908
zakia:
--- PHP Code: ---<?php require_once("dbc.php");?>
<?php require_once("functions.php");?>
<?php
if(isset($_POST['login']))
{
// Checking whether the Login form has been submitted
$err = array();
// Will hold our errors
if(!$_POST['username'] || !$_POST['password'])
$err[] = 'All the fields must be filled in!';
if(!count($err))
{
$_POST['username'] = mysql_real_escape_string($_POST['username']);
$_POST['password'] = mysql_real_escape_string($_POST['password']);
// Escaping all input data
$row = mysql_fetch_assoc(mysql_query("SELECT id,usr FROM tz_members WHERE usr='".$_POST['username']."' AND pass='".sha1($_POST['password'])."'"));
if($row['usr'])
{
header("Location:memberpage.php");
}
else $err[]='Wrong username and/or password!';
}
if($err){
$message=implode("<br/>",$err);
}
}
?>
--- End code ---
--- Code: ---<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<title>Login</title>
</head>
<body>
<div id="container">
<div id="form">
<form action="#" method="post" class="format">
<h4>Login</h4>
<div class="box">
<?php
if(!empty($message))
{
echo '<div class="err">'.$message.'</div>';
}
?>
<label>Username:</label>
<input name="username" type="text" class="textbox" id="user">
<label>password:</label>
<input name="password" type="password" class="textbox" id="password"><br/>
<label><input name="rememberMe" type="checkbox" id="rememberMe" value="">Remeber Me
<span>|<a href="#"> Forgot Password</a></span></label>
<br/>
<input name="login" type="submit" value="Login" class="btn" id="login"><span><a href="reg.php">Sign Up</a></span>
</div>
</form>
</div> <!--Form-->
</div>
</body>
</html>
--- End code ---
:(
:( :( :( stil not working. same problem MY DB is working well coz i have used this in other pages also.dont where going wrong.
dex2908:
Hi zakia,
I'm sure its not a big problem but i can't debug since i don't have the complete file. I need to know the structure of the db and all the files for me to debug. You can send me a complete set files(php and sql). Make sure you sql file contains all the create table statements and insert statements that resembles your current table. I'll get it fixed A.S.A.P. Cheer up dude!
Regards,
developer.dex2908
zakia:
How can i upload a file in php forum
Navigation
[0] Message Index
[#] Next page
Go to full version