出于学习目的,我正在尝试将数据从 HTML 表单插入 MySQL 数据库,这是我为表单获取的代码:
<form action="newmovie.php" method="post">
<p>Titulo: <input type="text" name="movieTitle"> </p>
<p>Año: <input type="text" name="movieYear"> </p>
<p>Director: <input type="text" name="movieDirector"> </p>
<p>Protagonista: <input type="text" name =movieProtagonist> </p>
<input type="submit" class="button" value="Agregar">
</form>
因此,在同一个网页中,我检查是否正在执行 POST:
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
include("connectDB.php");
$mySQL=new MySQL();
$movieTitle=$_GET['movieTitle'];
$movieDirector=$_GET['movieDirector'];
$movieYear=$_GET['movieYear'];
$movieProtagonist=$_GET['movieProtagonist'];
echo "INSERT INTO peliculas (titulo,director,year, protagonista) VALUES ('$movieTitle','$movieDirector','$movieYear', '$movieProtagonist')";
$queryResult=$mySQL->query("INSERT INTO peliculas (titulo,director,year, protagonista) VALUES ('$movieTitle','$movieDirector','$movieYear', '$movieProtagonist')");
echo "$queryResult";
}
?>
因此,插入已完成,但字段为空,这就是 echo 打印的内容:
INSERT INTO peliculas (titulo,director,year, protagonista) VALUES ('','','', '')
我的代码做错了什么?