![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<?
php
session_start ();
$username = $_POST [name];
$password = $_POST [password];
if ( $_POST [ ' name ' ] == "" )
{
echo " 请填写用户名<br><a href='login.php'>返回</a> " ;
} elseif ( $_POST [ ' password ' ] == "" )
{
echo " 请填写密码<br><a href='login.php'>返回</a> " ;
}
else
{
$link = mysql_connect ( " localhost:3306 " , " student " , " 123456 " );
mysql_select_db ( ' test ' );
$query = " select * from admin where username=' $username ' and password=' $password ' " ;
$result = mysql_query ( $query );
$row = mysql_num_rows ( $result );
if ( $row > 0 )
{
$_SESSION [ ' issession ' ] = true ;
$_SESSION [ ' username ' ] = $username ;
echo " <script language=\ " JavaScript\ " >\r\n " ;
echo " alert(\ " 登陆成功\ " );\r\n " ;
echo " location.replace(\ " success . php\ " );\r\n " ;
echo " </script> " ;
exit ;
}
else
{ echo " <script language=\ " JavaScript\ " >\r\n " ;
echo " alert(\ " 您输入的密码不正确!请重新输入!\ " );\r\n " ;
echo " history.back();\r\n " ;
echo " </script> " ;
exit ;
}
}
mysql_close ();
?>
session_start ();
$username = $_POST [name];
$password = $_POST [password];
if ( $_POST [ ' name ' ] == "" )
{
echo " 请填写用户名<br><a href='login.php'>返回</a> " ;
} elseif ( $_POST [ ' password ' ] == "" )
{
echo " 请填写密码<br><a href='login.php'>返回</a> " ;
}
else
{
$link = mysql_connect ( " localhost:3306 " , " student " , " 123456 " );
mysql_select_db ( ' test ' );
$query = " select * from admin where username=' $username ' and password=' $password ' " ;
$result = mysql_query ( $query );
$row = mysql_num_rows ( $result );
if ( $row > 0 )
{
$_SESSION [ ' issession ' ] = true ;
$_SESSION [ ' username ' ] = $username ;
echo " <script language=\ " JavaScript\ " >\r\n " ;
echo " alert(\ " 登陆成功\ " );\r\n " ;
echo " location.replace(\ " success . php\ " );\r\n " ;
echo " </script> " ;
exit ;
}
else
{ echo " <script language=\ " JavaScript\ " >\r\n " ;
echo " alert(\ " 您输入的密码不正确!请重新输入!\ " );\r\n " ;
echo " history.back();\r\n " ;
echo " </script> " ;
exit ;
}
}
mysql_close ();
?>