我一直收到以下错误,无法弄清楚出了什么问题。
注意:未定义的索引:第99行的C:\ xampp \ htdocs \ FYP \ resProcessing.php中的名称
错误与以下行有关:
$name = $_POST['name'];
以下是我的代码:
if ($quick_check != 0){
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$id = $row['id'];
$tablenum = $row['tablenum'];
$avail = $row['avail'];
$spots .= 'You just reserved table '.$tid.'.<br />';
$spots .= 'You only have 8 minutes to finish or your reservation will expire and the table will open up to other people.<br />';
}
$availNow = $avail - $num;
$sql = "UPDATE available SET avail='$availNow' WHERE id='$id' LIMIT 1";
$query = mysqli_query($connect, $sql);
$sql = "INSERT INTO reserves(tablenumber,numseats,restime) VALUES ('$tablenum','$num',now())";
$query = mysqli_query($connect, $sql);
$reserveID = mysqli_insert_id($connect);
$spots .= '<form name="confirmform" id="confirmform" method="post" onSubmit="return false;">';
$spots .= 'Full Name: <input type="text" name="name" id="name" required autofocus placeholder="Your Name" pattern="[a-zA-Z]+{3,}" title="Please enter your full name."></br>';
// hidden field holds the table name
$spots .= '<input id="tableNumber" type="hidden" value="'.$tablenum.'">';
// hidden field holds the number of seats
$spots .= '<input id="numSeats" type="hidden" value="'.$num.'">';
// hidden field holds the reserve insert id
$spots .= '<input id="reserveID" type="hidden" value="'.$reserveID.'">';
// On submit call js function
$spots .= '<button id="confirmbtn" onClick="confirmSeats();updateInfo();">Make Reservations</button></br>';
$name = $_POST['name'];
$sql = "UPDATE available SET name='$name' WHERE id='$id' LIMIT 1";
$query = mysqli_query($connect, $sql);
$spots .= '</form>';
$spots .= '<button id="cancelbtn" onClick="cancelReserve('.$reserveID.')">Cancel Reservation</button>';
} else {
$spots .= "Sorry, someone just reserved those. Try another table";
$reserveID = "open";
}
echo "$spots|$reserveID";
exit();
}
如果有人能提供帮助我真的很感激。谢谢!
答案 0 :(得分:1)
原因是POST请求不包含name
参数。
或者在您的情况下,HTTP请求类型不是POST。
尝试$name = $_REQUEST['name'];
- 它也会考虑GET变量(和Cookie)。
如果它没有帮助,请修复您的客户端(无论是HTML表单,JavaScript还是其他内容)。
您还可以在尝试访问之前检查POST变量是否已定义,例如:
if (isset($_POST['name']))
{
$name = $_POST['name'];
}
else
{
echo "Name is required";
// ...
}
答案 1 :(得分:0)