php
$con = mysqli_connect('localhost','root','root','test');
// 查
// $res = mysqli_query($con,"select * from info");
// 增 - 執(zhí)行成功返回true,執(zhí)行失敗返回false
// $res = mysqli_query($con,"insert info(id,name,age,sex) values(2,'zhaoliu',23,'男')");
// 改 - 執(zhí)行成功返回true廊谓,執(zhí)行失敗返回false
// $res = mysqli_query($con,"update info set sex='女',age=13 where id=4");
// var_dump($res);
// 刪 - 執(zhí)行成功返回true,執(zhí)行失敗返回false
// $res = mysqli_query($con,"delete from info where id=4");
// var_dump($res);
<?php
header("content-type:text/html;charset=utf8");
echo "<pre>";
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
$tel = $_POST["tel"];
// 連接數(shù)據(jù)庫
$con = mysqli_connect('localhost','root','root','test');
// 判斷用戶名
// 執(zhí)行查詢語句
$res = mysqli_query($con,"select * from user where username='$username'");
$row = mysqli_fetch_assoc($res);
if($row){
echo "用戶名被占用了";
}else{
// 執(zhí)行添加語句
$str = "insert user(username,password,email,tel) values
('$username','$password','$email','$tel')";
$bool = mysqli_query($con,$str);
if($bool){
// echo "注冊成功";
echo "<script>
alert('注冊成功');
location.href = 'login.html'
</script>";
}else{
// echo "注冊失敗";
echo "<script>
alert('注冊失敗');
location.href = './register.html'
</script>";
}
}