【发布时间】:2021-09-12 19:02:11
【问题描述】:
我是 PHP 新手,我正在尝试在我的数据库中输入详细信息。
我想将数据插入数据库的会话
<form method="post" action="">
<input name="p_date" type="date">
<input name="r_date" type="date">
</form>
if (!empty($_POST)) {
$_SESSION['p_date'] = $_POST['p_date'];
$_SESSION['r_date'] = $_POST['r_date'];
}
此代码,True 一侧的 Url 正在旋转,但无法将数据添加到数据库。 我哪里错了?
if(isset($_POST['dateSearch'])) {
$insert=$connect->prepare("Insert Into test (p_date,r_date) VALUES ('{$_SESSION['p_date']}','{$_SESSION['r_date']}'");
if($insert) {
header("Location:cars.php?Status=True");
}
else {
header("Location:cars.php?Status=False");
}
}
提前谢谢..
【问题讨论】:
-
你从不执行查询,只是准备它。
-
您也不应该将变量直接替换到查询中。在查询中放置占位符,然后使用
bind_param()将变量与占位符关联。 -
或
bindParam(),如果您使用的是 PDO。 -
你能把它写成代码吗?因为 PHP 在该领域我是新人:\
-
查看stackoverflow.com/questions/60174/… 和许多其他资源,它已经包含足够的示例供您使用
标签: php mysql session session-variables