1

我已经查看了其他一些类似的问题,但似乎仍然无法使其正常工作。FWIW,我没有收到任何特定的错误消息。

<?php

// Create connection
$con=mysqli_connect("localhost","username","password");
mysqli_select_db($con, "database");
//let's start our session, so we have access to stored data
session_start();

$class = mysqli_real_escape_string($_SESSION['exclass']);
$fullname = mysqli_real_escape_string($_SESSION['fullname']);
$june = mysqli_real_escape_string($_SESSION['June']);
$july = mysqli_real_escape_string($_SESSION['July']);
$email = mysqli_real_escape_string($_POST['email']);
$phone = mysqli_real_escape_string($_POST['phone']);

//let's create the query
$insert_query = "INSERT INTO Responses (class,fullname,June,July,email,phone) VALUES ('$class','$fullname',$june,$july,'$email','$phone',)";

//let's run the query
$result = mysqli_query($con,$insert_query);

if($result){
    echo "Your response has been recorded. Thank you!";

}else{

    printf("Insert failed: %s\n", mysqli_error());
}
?>
4

2 回答 2

3

MySQL 不支持尾随逗号表示法。

因此,替换:

,'$phone',)

,'$phone')

此外,添加回退条件以查看错误输出缓冲区:

mysqli_query($con, $insert_query) or die(mysqli_error($con));

于 2013-03-07T17:28:55.707 回答
1
"INSERT INTO Responses (class,fullname,June,July,email,phone) VALUES    ('$class','$fullname',$june,$july,'$email','$phone',<--- LOOK AT THIS COMMA)

这很可能会解释无法插入数据库的原因。从 SQL 字符串中删除逗号,它将正确解析。

于 2013-03-07T17:29:06.287 回答