Login form with mysql destroys all php queries in next page
Posted: Mon Jan 19, 2004 10:31 am
I created a login script which authenticates users but after submiting it i get The message "Right Password" on the top and all other data requests are destroyed.The return die errors such as database not selected while that page was working fine before the login form submition!
This the code:
And this is the form code:
This the code:
Code: Select all
<?php
session_start();
header("Cache-control: private");
$_SESSION['logged_in'] = 0;
$_SESSION['session_id'] = 0;
error_reporting(E_ALL);
if(isset($HTTP_POST_VARS['submit'])){
if((strlen($HTTP_POST_VARS['username'])>0) AND (strlen($HTTP_POST_VARS['password'])>0)){
require_once ("../../w/connect.inc");//einai sto music.hxotpon.net/blabla.php
$query = "SELECT username,password FROM customers";
$query_result = mysql_query ($query);
if($query_result)
{
$login_status=0
$a=0;
while($row = @ mysql_fetch_array($query_result))
{
if(($row['username']==$username) AND ($row['password']==$password))
{
$logged_in = 1;
$login_status=1;//user authenticated
}
if(($row['username']==$username) AND ($row['password']!=$password))
{
$logged_in = 2;//wrong password
}
}
if($login_status==1)
{
$rand=rand(1,9);
$session_id=$rand.substr(md5($REMOTE_ADDR), 0, 11+$rand);
$session_id.=substr(md5(rand(1,1000000)), rand(1,32-$rand), 21-$rand);
session_id($session_id);
echo '<font color="green"> Σωστό password </font>';
echo $session_id;
}
if($logged_in==2)
{
echo '<font color="red"> Wrong password</font>';
}
if($logged_in==0)
{
echo '<font color="red">Try Again</font>';
}
}else{
echo '<b><font color="red"> Try Again </font></b>';
}//telos if($query_result)
mysql_close();
}else{
echo '<font color="red"> You left empty one of the fields! </font>';
}//telos if(strlen...
}
?>Code: Select all
<form action="index.php" method="post" name="login" class="text11" id="login">
<p><strong> Είσοδος (email):
<input name="username" type="text" class="info2" id="username">
</strong><strong>Password:
<input name="password" type="password" class="info2" id="password">
<input name="submit" type="submit" class="red" id="submit" value="Είσοδος">
</strong></p>
</form>