使用与先前查询相同的代码时,无法在SQL表中插入数据

时间:2016-09-17 12:08:32

标签: php mysql

我需要将两个数据插入两个不同的表中。它成功地使用其中一个表而不是第二个表。我已经使用或死了mysqli_error来查看它是否会告诉我错误,但它没有显示任何内容。请参阅以下代码:

$sql = "INSERT INTO ticketUsers 
            (name, emailAddress, password) 
            SELECT * FROM (SELECT '$name', '$emailAddress', '$dbPassword') AS tmp
            WHERE NOT EXISTS (
                                SELECT name 
                                FROM ticketUsers 
                                WHERE emailAddress = '$emailAddress'
                            ) 
            LIMIT 1"; 
$query = mysqli_query($connection, $sql);

if($query)
{
    echo "Success entering ticket Users";
}
else if(!$result)
{
   echo "Cant enter information";
}

$sql = "INSERT INTO tickets 
                (id, emailAddress, urgency, subject, 
                 description, relevantURL, status) 
        VALUES ('$id', '$emailAddress', '$username', '$urgency', 
                '$subject', '$description2', '$relevantURL', 'Open')";

$query = mysqli_query($connection, $sql);

if($query)
{
    echo "Success entering tickts";
}
else if(!$result)
{
   echo "Cant enter information";
}

if (!sql) 
{
echo "There has been an error creating your ticket.";
}

1 个答案:

答案 0 :(得分:2)

在第二个查询中,您尝试在包含7个字段8值的表中插入。

我认为你不想插入' $ username'在查询中。