我编写了这段代码,它应该将一堆值插入到数据库中,但是每当我运行此代码时,它都会显示“致命错误:未捕获的异常‘PDOException’,消息为‘SQLSTATE[42000]:语法错误或访问冲突:1064您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,以了解要使用的正确语法“附近”和“PDOException:SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 有错误语法;检查与您的 MySQL 服务器版本相对应的手册,以获取在附近使用的正确语法。有人可以帮忙吗?我的代码,根据这些错误消息,错误在 INSERT 部分的某处:mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);if (session_status() == PHP_SESSION_NONE) { session_start();}function getValue1() { if (!isset($_GET[r])) { return false; $referral_code = "-"; } return $_GET[r]; $referral_code = $_GET[r];}// initializing variables$username = "";$email = "";$errors = array(); require("php_db_info.php"); $dsn = 'mysql:host=127.0.0.1;dbname=user_db;charset=utf8'; $conn = new PDO($dsn, $username1, $password); $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);// REGISTER USERif (isset($_POST['reg_user'])) { // receive all input values from the form $username = $_POST['username']; $email = $_POST['email']; $password_1 = $_POST['password_1']; $password_2 = $_POST['password_2']; if (getValue('r')) { $referral_code = $_GET['r'];} else { $referral_code = "-"; } if (empty($username)) { array_push($errors, "Username is required."); } if (empty($email)) { array_push($errors, "Email is required."); } if (empty($password_1)) { array_push($errors, "Password is required."); } if ($password_1 != $password_2) { array_push($errors, "The two passwords do not match."); } if(preg_match("/[^a-zA-Z0-9_-]/i", $username)) { array_push($errors, "You can only use letters, numbers, underscores and dashes."); } if (strlen($username) <= 1) { array_push($errors, "Your username must have at least 2 characters."); } if (strlen($username) >= 22) { array_push($errors, "Your username must have below 22 characters."); } require "server_bannedwords.php";
1 回答
- 1 回答
- 0 关注
- 304 浏览
添加回答
举报
0/150
提交
取消