Jump to content

Coding bugs(plz help)


cty

Recommended Posts

my problem is :whenever i log in ,it always shown 'You are not log in'.
Never show "You are logged in as :xxx"

For example:i do a testing,i input username:abc and password:1234 in "user" table.
Next,i try to log in using abc and 1234.But,still shown 'You are not log in'

can anyone tell me which part have bugs?or how i edit the code?

I already use a phpeditor to check bugs,but no warning shown.

Hope u able to help me.
TQ
------------------------------------------------------------------------------
//login.html
<html>

<head>


<title>Login here</title>
</head>

<body>

<form method="POST" action="login.php">


Username
<input type="text" name="username" size="20"></p>
Password
<p><input type="text" name="password" size="20"></p>

<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>
----------------------------------------------------------------------

//login.php

<?php
session_start();

if(isset($_POST['username'])&&isset($_POST['password']))
{

$username=$_POST['username'];
$password=$_POST['password'];

$db=new mysqli('localhost','root','','kelly');

if(mysqli_connect_errno()){
echo 'Connection to database failed:'.mysqli_connect_error();
exit();
}

$query='select* from user '
."where username='$username'"
."and password=sha1('$password')";

$result=$db->query($query);



if($result->num_rows >0)
{
$_SESSION['valid_user']=$username;
}

$db->close();
}
?>

<html>
<body>
<h1>Home Page</h1>
<?php

if(isset($_SESSION['valid_user']))
{
echo'You are logged in as :'.$_SESSION['valid_user'].'<br />';
}
else
{
echo'You are not log in';
}

?>

-----------------------------------------------------------------------//end
Link to comment
Share on other sites

[code]
//login.html
<html>

<head>


<title>Login here</title>
</head>

<body>

<form method="POST" action="login.php">
 
 
  Username
  <input type="text" name="username" size="20"></p>
  Password
  <p><input type="text" name="password" size="20"></p>
 
<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>
----------------------------------------------------------------------

//login.php

<?php
session_start();

if($_POST['B1']) {

$username=$_POST['username'];
$password=$_POST['password'];

$db=new mysqli('localhost','root','','kelly');

if(mysqli_connect_errno()){
echo 'Connection to database failed:'.mysqli_connect_error();
exit();
}

$query='select* from user '
."where username='$username'"
."and password=sha1('$password')";

$result=$db->query($query);



if($result->num_rows >0)
{
$_SESSION['valid_user']=$username;
}

$db->close();
}
?>

<html>
<body>
<h1>Home Page</h1>
<?php

if(isset($_SESSION['valid_user']))
{
  echo'You are logged in as :'.$_SESSION['valid_user'].'
';
}
else
{
  echo'You are not log in';
}

?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.