使用PHP实现登录与注册功能以及使用PHP读取mysql资料库——以表格形式展现资料
登录窗口
客户名:
密码:
后台登录处理
$uid = $_POST[“uid”];
$pwd = $_POST[“pwd”];
$db = new MySQLi(“localhost”,”root”,””,”0710_info”);
if(mysqli_connect_error()){
die(“连接失败”);
}
$sql = “select pwd from users where uid='{$uid}'”;
//echo $sql;
$result = $db->query($sql);
$arr = $result->fetch_row();
//以免sql注入进攻
if($arr[0]==$pwd && !empty($pwd)){
//跳转到主窗口(php方法)
header(“location:register_system.php”);
//JS跳转页面方法
/*echo “
window.location.href=’register_system.php’
”;*/
}else{
header(“location:login_system.php”);
}
?>
注册窗口
客户注册
客户名:
登录密码:
姓名:
性别:
男
女
JS表单验证
function check(){
var uid = document.getElementsByTagName(“input”)[0].value;
if(uid == “”){
alert(“请输入客户名!”);
return false;
}
var pwd = document.getElementsByTagName(“input”)[1].value;
if(pwd == “”){
alert(“请输入密码!”);
return false;
}
var name = document.getElementsByTagName(“input”)[2].value;
if(name == “”){
alert(“请输入姓名!”);
return false;
}
}
后台注册处理
$uid = $_POST[“uid”];
$pwd = $_POST[“pwd”];
$name = $_POST[“name”];
$sex = $_POST[“sex”];
$db = new MySQLi(“localhost”,”root”,””,”0710_info”);
if(mysqli_connect_error()){
die(“连接失败”);
}
$sql = “insert into users values(‘{$uid}’,'{$pwd}’,'{$name}’,{$sex})”;
$r = $db->query($sql);
if($r){
echo “注册*!”;
}else{
echo “注册失败!”;
}
?>
PHP读取mysql资料库——以表格形式展现资料
代号 | 姓名 | 性别 | *日 | 民族 |
{$v[0]} | {$v[1]} | {$sex} | {$v[3]} | {$v[4]} |