mysqli insert不起作用

kxe2p93d  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(529)

“我已经搜索过了,但没有找到这个问题的答案。实际上,我想用php/html表单在数据库中添加一个数据。这是一个方法=“post”,我得到的数据似乎是正确的。。但插入根本不起作用。我的问题不好吗?或者是数据库的问题?
回显不会返回空值。
非常感谢你回答我的问题!:)这是我的密码:

$sport = $_POST['sport'];
$level = $_POST['level'];
$date = $_POST['date'];
$firsthour = $_POST['first'];
$lasthour = $_POST['last'];

echo "sport: " . $sport . " Level" . $level . " Date ". $date . " first hour" . $firsthour. " last hour " . $lasthour;

$connexion = mysqli_connect("localhost", "root", "", "database");
$reqadd = "insert into commandes ('name', 'id_sport', 'id_niveau', 'date', 'heure_début', 'heure_fin') values ('Amendera Lochan','$sport','$level','$date','$firsthour':00,'$lasthour':00)";
echo $reqadd;
mysqli_query($connexion, $reqadd);
yacmzcpb

yacmzcpb1#

你应该用这个“`”来 Package 你的列名,如下所示:

$sport = $_POST['sport'];
$level = $_POST['level'];
$date = $_POST['date'];
$firsthour = $_POST['first'];
$lasthour = $_POST['last'];

echo "sport: " . $sport . " Level" . $level . " Date ". $date . " first hour" . $firsthour. " last hour " . $lasthour;

$connexion = mysqli_connect("localhost", "root", "", "database");
$reqadd = "INSERT INTO commandes (`name`, `id_sport`, `id_niveau`, `date`, `heure_début`, `heure_fin`) values ('Amendera Lochan','{$sport}','{$level}','{$date}','{$firsthour}','{$lasthour}')";

mysqli_query($connexion, $reqadd);

相关问题