<?php
error_reporting(0);
//通过帐户名和密码登录连接数据库
$mysql_servername = "127.0.0.1"; //主机地址
$mysql_username = "root"; //数据库用户名
$mysql_password =""; //数据库密码
$mysql_database ="manfeng_game_test"; //数据库
$database_table="system_user_table";
$conn = mysql_connect($mysql_servername, $mysql_username, $mysql_password);
if (!$conn)
{ die('Could not connect: ' . mysql_error());
}else{echo 'connect mysql ok!' . '<br/>';}
$db_selected = mysql_select_db($mysql_database,$conn);
if (!$db_selected)
{ die ("Can\'t use db : " . mysql_error());
mysql_close($con);
}else{echo 'db select ok!' . '<br/>';}
/*对所所输入的登录用户变量进行值过滤*/
$name = addslashes(htmlspecialchars($_POST['username']));
$passsword = addslashes(htmlspecialchars($_POST['password']));
echo 'User = ' . $name .'<br/>';
echo 'Password = ' . $passsword .'<br/>';
//if (1){
$sql = "SELECT member_type FROM $database_table WHERE member_name = '$name' and member_password='$passsword'";
$res = mysql_query($sql);
$row = mysql_fetch_row($res); #将获得的查询结果作为一个数组保存起来,这个数组将会只有一个下标变量
//print_r($row);
//将唯一的一条数组记录作为SESSION变量保存
session_start();
$_SESSION["member_type"]=$row[0];
//echo $_SESSION["member_type"];
//echo '<br /><a href="http://localhost/wordpress/JEasyUI/User-and-Email-Reply/index.php">index</a>';
//mysql_num_rowsPHP函数,取得查询结果集当中行的数目。此命令只对SELECT语句正确有效。
$rows = mysql_num_rows($res);
if($rows){
//成功进入跳转页面,注意路径
echo "<script>location.href='http://localhost/wordpress//JEasyUI/User-and-Email-Reply/index.php';</script>";
exit;
}else{
echo "<script language=javascript charset= \"utf-8\">alert('UserName or Password Error!');history.back(); </script>";}
?>
转载于:https://my.oschina.net/ajian2014/blog/324432