我有 3 个 php 文件,第一个文件名为 mysql_login_an.php:
<?php
if(!mysql_connect('localhost','root','root') || !mysql_select_db('d_database')){
echo mysql_error();
}
?>
第二个文件名为 mysql_form.php
<?php
session_start();
require 'mysql_login_an.php';
if(isset($_GET['user'])&&isset($_GET['password']))
{
$user=$_GET['user'];
$password=$_GET['password'];
$password_hash=md5($password);
$user_hash=md5($user);
if(!empty($user) && !empty($password))
{
$query="SELECT `id` FROM `users` WHERE `username`='$user' and `password`='$password'";
if($query_run=mysql_query($query))
{
$mysql_num_rows=mysql_num_rows($query_run);
if($mysql_num_rows==0)
{
echo 'invalid user';
}
elseif($mysql_num_rows>=1)
{
$user_id=mysql_result($query_run,0,`id`);
$_SESSION['user_id']=$user_id;
Header('Location:login_success.php');
}
}
}
else
{
echo 'error';
}
}
?>
<form action='#' method='GET'>
user <input type='text' name='user'><br><br>
pass <input type='password' name='password'><br>
<input type='submit' value='send'>
</form>
第三个文件名是function.php
<?php
require 'mysql_form.php';
function delete_cookie()
{
if(isset($_GET['action'])&&$_GET['action']=='logout')
{
require 'mysql_form.php';
session_destroy();
header('location:mysql_form.php');
}
else
{
$firstname=get_user_info('firstname');
$surname=get_user_info('surname');
echo "hello $firstname $surname ,U are login successfully <a href='mysql_form.php?action=logout'>log out </a>";
}
}
delete_cookie();
function get_user_info($field)
{
$query="SELECT $field FROM `users` WHERE `id`='".$_SESSION['user_id']."'";
if($query_run=mysql_query($query))
{
if($query_result=mysql_result($query_run,0,$field)){
return $query_result;
}
}
}
?>
我希望它输出名字姓氏(在我的数据库中)和注销按钮。但它也显示登录表单。如何解决这个问题。这是我登录 http://upanh.com/view/时的屏幕图片?s=上传&id=3rr49kaganc