html:
<body>
<div class="register">
<h1>注册成为新用户</h1>
<form action="register.php" method="POST">
<h4>基本信息:</h4>
<label for="username">用户名:</label>
<input type="text" name="username">
<br>
<label for="password">密码:</label>
<input type="text" name="password">
<br>
<label for="email">邮箱:</label>
<input type="text" name="email">
<br>
<h4>联系方式:</h4>
<label for="qq">QQ:</label>
<input type="text" name="qq">
<br>
<label for="phone">手机号码:</label>
<input type="text" name="phone">
<br>
<label for="city">所在城市:</label>
<input type="text" name="city">
<br>
<br>
<br>
<button type="submit" name="submit">注册</button>
</div>
</form>
</body>
css:
html{
position: relative;
line-height: 30px;
background: rgba(173, 216, 230, 0.5);
}
input{
border-radius: 20px;
border: 1px solid lightblue;
}
.register{
position: absolute;
width:500px;
margin-left: -250px;
padding: 50px;
left: 50%;
border-radius: 30px;
}
.register h1{
text-align: center;
color: rgb(238, 65, 12)
}
label{
display: inline-block;
width: 180px;
text-align: center;
}
button{
height: 40px;width: 150px;
border: none;
background: rgba(240, 128, 128, 0.6);
font-size: 20px;
font-weight: bold;
margin-left: 130px;
}
php:
<?php
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$qq=$_POST['qq'];
$phone=$_POST['phone'];
$city=$_POST['city'];
$dbc=mysqli_connect('127.0.0.1','root','','register') or die('连接数据库错误!');
$query="INSERT INTO user_information VALUES('$username','$password','$email','$qq','$phone','$city')";
$result=mysqli_query($dbc,$query) or die('数据请求失败!');
mysqli_close($dbc);
echo '<script>
alert("您已注册成功!请返回并登录");
window.location.href="#";
</script>';
?>
此外还涉及sql数据库中新建表时列的设置,对于不同的列需要对应不同的排序规则和类型,暂不熟悉,后续用到再补充。此外还有sql内数据的编号、删除功能未学习。
此为学完第一二章,初步了解php和sql数据库使用的总结。
写完此文后发现的高级完整版,本文后续有需要会按此完善。