-1

到目前为止,这是我的代码...

if (isset($_POST['projectName']))
{

    $projectName = $_POST['projectName'];
    $dueDate = $_POST['dueDate'];
    $description = $_POST['description'];
    $requestor = $_POST['requestor'];
    $status = $_POST['status'];

    //Update into the DB
    $updateSQL = mysql_query("INSERT INTO projects 
                                (projectName, 
                                dueDate, 
                                description, 
                                requestor,
                                status
                                )
                                VALUES 
                                ('".$projectName."','
                                ".$dueDate."','
                                ".$description."','
                                ".$requestor."','
                                ".$status."')");


    /*
    header('Location:manage.php?update=insertSuccess');
    exit();
    */  

}

除了 $status 之外,每个值都已成功插入数据库。我在这里错过了什么吗?

4

1 回答 1

1

语法看起来不错,但是...

  • 你没有发现错误,所以它可能是某种列约束。
$updateSQL = mysql_query("INSERT...") or die(mysql_error());

将捕获这些错误。

这里有一些东西可以帮助你开始:

$link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');

/* check connection */
if (!$link) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$stmt = mysqli_prepare($link, "INSERT INTO projects (projectName, dueDate, description, requestor, status) VALUES (?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssss', $projectName, $dueDate, $description, $requestor, $status);

/* execute prepared statement */
mysqli_stmt_execute($stmt);

printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt));

/* close statement and connection */
mysqli_stmt_close($stmt);

/* close connection */
mysqli_close($link);
于 2013-01-08T21:26:53.173 回答