php - 为什么$ _POST变量数据没有插入我的MySQL表?

时间:2016-06-20 16:07:45

标签: php mysql database mysqli

我想从$ _POST中获取数据并将其放入表中。我创建表没有问题但是插入数据本身存在问题。 这是我的代码:

$name = $_POST["fullName"];
$userType = $_POST["userType"];
$emailAddress = $_POST["emailAddress"];
$phoneNumber = $_POST["phoneNumber"];
$preferredContact = $_POST["preferredContactMethod"];
$location = $_POST["location"];
$desiredService = $_POST["desiredService"];
$details = $_POST["description"];

$compressed_name = str_replace(" ", "", $name);

$conn = mysqli_connect("localhost:8889", "root", "root", "clientsDB");

$sql = "CREATE TABLE " . $compressed_name . " (
        full_name VARCHAR(30),
        user_type VARCHAR(30),
        email_address VARCHAR(50),
        phone_number VARCHAR(30),
        preferred_contact VARCHAR(50),
        location VARCHAR(100),
        desired_service VARCHAR(30),
        details VARCHAR(540));";

if (mysqli_query($conn, $sql)) { echo "Successfully made the table."; }

$sql = "INSERT INTO '$compressed_name' (`full_name`, 
        `user_type`, 
        `email_address`, 
        `phone_number`, 
        `preferred_contact`, 
        `location`, 
        `desired_service`, 
        `details`) VALUES ('$name', 
        '$userType', 
        '$emailAddress', 
        '$phoneNumber',           
        '$preferredContact', 
        '$location', 
        '$desiredService', 
        '$details');";

if (mysql_query($conn, $sql)) { echo "Successfully inserted data into the table."; }

mysql_close($conn);

此问题被标记为关于如何在不同环境中查找MySQL错误的问题的副本。我不想在不同的环境中得到错误 - 我想知道如何插入数据!

0 个答案:

没有答案