我的代码中的未定义索引,我真的不知道这里的问题在哪里... 这是我的HTML代码
<?php
$host = "localhost";
$user = "root";
$password = "";
$database = "db_ass";
$con = mysqli_connect($host,$user,$password);
if(!$con)
{
echo 'Not Connected to Server';
}
if(!mysqli_select_db($con,'db_ass'))
{
echo 'Database Not Selected';
}
$firstname= $_POST['fname'];
$lastname= $_POST['lname'];
$course= $_POST['course'];
$yr= $_POST['year'];
$sql = "INSERT INTO students (firstname,lastname,course,year) VALUES ('$firstname', '$lastname', '$course','$yr')";
if(!mysqli_query($con,$sql))
{
echo "Not inserted";
}
else
{
echo "Inserted";
}
?>
它总是在第20-23行中说未定义的索引
$firstname= $_POST['fname'];
$lastname= $_POST['lname'];
$course= $_POST['course'];
$yr= $_POST['year'];
$sql = "INSERT INTO students (firstname,lastname,course,year) VALUES ('$firstname', '$lastname', '$course','$yr')";
请帮助我T-T
答案 0 :(得分:-2)
我认为您应该从值规范中的变量中删除逗号。