php - PHP 错误:致命错误:未捕获的 PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;
问题描述
我正在尝试为我的网站编写注册脚本。这个脚本所做的只是从页面获取用户输入,并将其发送到 MySQL。我正在使用 PDO,因为它应该更安全,但我找不到语法错误。
注册3.inc.php
<?php
// create a db connection
//initializing variables <br/><br/>
$FirstName = "";<br/>
$LastName = "";<br/>
$userName = "";<br/>
$userEmail = "";<br/>
$cUserEmail = "";<br/>
$password = "";<br/>
$cPassword = "";<br/>
$userAddress = "";<br/>
$userAddress2 = "";<br/>
$userZip = "";<br/>
$userCity = "";<br/>
$userState = "";<br/>
$userPhone = "";<br/>
$userID = "";<br/>
$today = date("r");<br/>
//defining variables
if(isset($_POST['FirstName'])){$FirstName = $_POST['FirstName'];}; <br/>
if(isset($_POST['LastName'])){$LastName= $_POST['LastName'];};<br/>
if(isset($_POST['userName'])){$userName = $_POST['userName'];};<br/>
if(isset($_POST['userEmail'])){$UserEmail = $_POST['userEmail'];};<br/>
if(isset($_POST['cUserEmail'])){$cUserEmail = $_POST['cUserEmail'];};<br/>
if(isset($_POST['password'])){$password = $_POST['password'];};<br/>
if(isset($_POST['cPassword'])){$cPassword = $_POST['cPassword'];};<br/>
if(isset($_POST['userAddress'])){$userAddress = $_POST['userAddress'];};<br/>
if(isset($_POST['userAddress2'])){$userAddress2 = $_POST['userAddress2'];};<br/>
if(isset($_POST['userZip'])){$userZip = $_POST['userZip'];};<br/>
if(isset($_POST['userCity'])){$userCity = $_POST['userCity'];};<br/>
if(isset($_POST['userState'])){$userState = $_POST['userState'];};<br/>
if(isset($_POST['userPhone'])){$userPhone = $_POST['userPhone'];};<br/>
$query = "INSERT INTO userprofile (userFirstName, userLastName, userCity, userState, userZip, userRegDate, userPhone, userAddress, userAddress2, userEmail, userName) <br/>
VALUES ($FirstName,$LastName,$userCity,$userState,$userZip,$today,$userPhone,$userAddress,$userAddress2,$userEmail,$userName)";
$connect->exec($query);
echo "<script> alert('Account successfully created!'); window.location='index.html'</script>";
解决方案
推荐阅读
- java - 比较两个 Date() 的正确方法是什么?
- xml - 如何在 XSLT 中获得前 3 个结果
- java - 获取 java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 in react native
- jmeter - 确定性能测试场景
- node.js - 使用 Node.js 连接到 SQL Server 不起作用
- ios - 当我在后台时打开哪个应用程序?
- javascript - 多重数据过滤
- javascript - 在javascript中突出显示文本按钮
- python - 如何在 python 虚拟环境中安装 rasa x - 使用 pip3 的 Rasax 安装错误
- c# - 使用像大纲步骤这样的背景步骤