我希望用户的输入进入数据库,但它不起作用。我有一个 sql 代码工作块,可以将数据插入数据库,但运行时我不断收到“未定义”错误。这是完整运行的sql代码
<?php
require 'creationlink.php';
$quizname = $_POST['name'];
$quest = $_POST['question'];
$ans1 = $_POST['answer1'];
$ans2 = $_POST['answer2'];
$ans3 = $_POST['answer3'];
$ans4 = $_POST['answer4'];
$correct = $_POST['A'];
//initiates connection with database with creation file
$sql = "INSERT INTO Quiz(question, answer1, answer2, answer3, answer4, correct) VALUES (?, ?, ?, ?, ?, ?)";
if($stmt = mysqli_prepare($conn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ssssss", $quest, $ans1, $ans2, $ans3, $ans4, $correct);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
echo "Records inserted successfully.";
} else{
echo "ERROR: Could not execute query: $sql. " . mysqli_error($conn);
}
}
else{
echo "ERROR: Could not prepare query: $sql. " . mysqli_error($conn);
}
?>
这是我希望应用 sql 的代码,它只是一个简单的测验模板,根据用户输入进行迭代。
紫衣仙女
相关分类