Mysqli INSERT不起作用

时间:2018-05-27 11:11:28

标签: php mysql mysqli insert

'我已经搜索了这个,但没有找到这个问题的任何答案。实际上,我想在我的数据库中使用PHP / HTML表单添加数据。这是一个方法=“帖子”,我的数据似乎是正确的..但插入根本不起作用。我的查询不好吗?或者是数据库的东西?

echo不会返回null值。

非常感谢您回答我的问题! :)这是我的代码:

$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);

1 个答案:

答案 0 :(得分:0)

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

$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);