首页 > 解决方案 > 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>";

标签: phpmysqlpost

解决方案


推荐阅读