所以我一直在尝试这几个小时,并且看了一遍,但找不到让它工作的方法 . 我知道这个问题与_POST和_GET有关,但我似乎无法修复它 . 每次我点击提交按钮时,我都会收到一个错误,告诉我我的查询除了$ ID之外还有所有信息,这是空白的 . 当我在语句上方回显时,ID正确地从URL中检索并显示正确的数字,但是当我尝试将变量插入到我的查询中时,它不会插入任何内容 . 当我切换isset语句以检查id中的值时,它不会运行,这意味着在_POST数组中没有定义id . 如何让我的查询包含ID以及所有其他数据?
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if($conn->connect_error) die($conn->connect_error);
$id="";
if (isset($_GET["id"]))
$id = $_GET["id"];
echo "$id";
if (isset($_POST['title']) &&
isset($_POST['score']) &&
isset($_POST['body']) &&
isset($_POST['date']) &&
isset($_POST['customer']))
{
$title = get_post($conn, 'title');
$score = get_post($conn, 'score');
$body = get_post($conn, 'body');
$date = get_post($conn, 'date');
$customer = get_post($conn, 'customer');
$query = "INSERT INTO review VALUES" .
"(NULL, '$title', '$score', '$body', '$date', '$id', '$customer')";
$result = $conn->query($query);
if (!$result){
echo "INSERT failed: $query<br>" .
$conn->error . "<br><br>";
}else{
header("Refresh: 0; URL= AddReviewSuccess.php");
}
}
echo html......
......FORM DATA THAT HAS method='post'......
......end echo
function get_post($conn, $var){
return $conn->real_escape_string($_POST[$var]);
}
?>