<form action="submit.php" method="post"> <label for="username">用户名:</label> <input type="text" id="username" name="username"> <br> <label for="password">密码:</label> <input type="password" id="password" name="password"> <br> <input type="submit" value="提交"> </form>
$username = $_POST['username']; $password = $_POST['password'];
//获取用户名和密码 $username = $_POST['username']; $password = $_POST['password']; //验证用户名和密码 if($username == 'admin' && $password == '123456') { echo '登录成功'; } else { echo '登录失败'; }
//连接MySQL数据库 $conn = new mysqli('localhost', 'username', 'password', 'database_name'); //查询数据 $result = $conn->query('SELECT * FROM users'); //输出数据 while($row = $result->fetch_assoc()) { echo '用户名:' . $row['username'] . ',密码:' . $row['password'] . '<br>'; }
<?php //连接MySQL数据库 $conn = new mysqli('localhost', 'username', 'password', 'database_name'); //获取用户名、密码以及确认密码 $username = $_POST['username']; $password = $_POST['password']; $confirm_password = $_POST['confirm_password']; //判断密码是否相同 if($password != $confirm_password) { echo '两次密码不一致!'; } else { //将用户名和密码保存到数据库中 $sql = "INSERT INTO users (username, password) VALUES ('$username', '$password')"; if ($conn->query($sql) === TRUE) { echo '注册成功!'; } else { echo '注册失败:' . $conn->error; } } ?> <form action="" method="post"> <label for="username">用户名:</label> <input type="text" id="username" name="username"> <br> <label for="password">密码:</label> <input type="password" id="password" name="password"> <br> <label for="confirm_password">确认密码:</label> <input type="password" id="confirm_password" name="confirm_password"> <br> <input type="submit" value="注册"> </form>