【问题标题】:Mysqli INSERT doesn't workMysqli INSERT 不起作用
【发布时间】:2018-05-27 11:11:28
【问题描述】:

'我已经搜索过这个,但没有找到这个问题的任何答案。实际上,我想使用 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);

【问题讨论】:

标签: php mysql mysqli insert


【解决方案1】:

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

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

【讨论】:

  • 你应该为你的答案添加一个清晰的描述和解释,而不是“试试这个”.only。
猜你喜欢
  • 1970-01-01
  • 2014-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-12
  • 2013-04-14
相关资源
最近更新 更多