赞
踩
<?php
echo "hello World!";
用于测试的小皮服务器
更改了模拟服务器地址,所以访问失败
<?php // 连接数据库 $servername = "localhost"; $username = "root"; $password = "12345"; $dbname = "test"; $conn = mysqli_connect($servername, $username, $password, $dbname); // 检查连接 if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } // 处理登录表单提交 if ($_SERVER['REQUEST_METHOD'] === 'POST') { $email = $_POST['email']; $password = $_POST['password']; // 查询用户是否存在 $sql = "SELECT * FROM user WHERE email='$email'"; $result = mysqli_query($conn, $sql); //邮箱正确 if (mysqli_num_rows($result) === 1) { // 验证密码是否正确 $user = mysqli_fetch_assoc($result); // 调试用:打印出从数据库中检索的用户数据 var_dump($user['password']); var_dump($password); if ($password === $user['password']) { var_dump('登录成功'); // 登录成功 session_start(); $_SESSION['user_id'] = $user['id']; //跳转页面 header('Location: dashboard.php'); exit(); } else { // 调试用:打印出密码验证参数的值 // var_dump($password, $user['password']); // 密码不正确 $error = 'Invalid password'; } } else { // 用户不存在 $error = 'User not found'; } } ?> <!DOCTYPE html> <html> <head> <title>Login</title> </head> <body> <?php if (isset($error)): ?> <p><?php echo $error; ?></p> <?php endif; ?> <form method="post"> <label for="email">Email</label> <input type="email" name="email" required> <label for="password">Password</label> <input type="password" name="password" required> <button type="submit">Login</button> </form> </body> </html>
<?php
echo 'hello';
CREATE DATABASE test;
USE test;
CREATE TABLE user (
id INT(11) NOT NULL AUTO_INCREMENT,
email VARCHAR(50) NOT NULL,
password VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO user (email, password) VALUES ('test@example.com', '12345');
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。