我編寫了這段代碼,它應該將一堆值插入到數據庫中,但是每當我運行此代碼時,它都會顯示“致命錯誤:未捕獲的異?!甈DOException’,消息為‘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 回答
- 0 關注
- 336 瀏覽
添加回答
舉報
0/150
提交
取消