提问人:Anynomous 提问时间:11/6/2022 最后编辑:DharmanAnynomous 更新时间:11/7/2022 访问量:56
如何显示警报消息 [已关闭]
How to display alert messages [closed]
问:
目前,我希望在单击按钮后弹出警报消息,但它不起作用。数据保存在数据库中,但不会弹出警报消息。
if (isset($_POST['add_reminder']))
{
$user_id = $_SESSION['user_id'];
$email = $_POST['email'];
$reminder_name = $_POST['reminder_name'];
$reminder_date = $_POST['reminder_date'];
$reminder_amount = $_POST['reminder_amount'];
$add_notes = $_POST['add_notes'];
$rmd = "INSERT INTO reminder (user_id, email, reminder_name,reminder_date,reminder_amount,add_notes) VALUES ('$user_id', '$email', '$reminder_name','$reminder_date','$reminder_amount','$add_notes') ";
if(mysqli_query($con,$rmd))
{
echo"<script>alert('Your reminder has been saved!');</script>";
header('location:add_reminder.php');
}
else{
die("Something went wrong");
}
答:
0赞
rauwitt
11/6/2022
#1
末尾缺少一个括号,Javascript 和 PHP 代码的分隔不正确。出于安全原因,请在 SQL 查询中使用预准备语句。
我不知道你的表的结构,所以在带有“bind_param”的行中,也许必须输入“i”表示整数,而不是“s”表示字符串。数据库连接的定义与“$conn = ...”必须根据您的值进行调整。
<FORM action='' method='POST' enctype='multipart/form-data'>
<button type='submit' name='add_reminder'>click</button>
<?php
if (isset($_POST['add_reminder']))
{
$user_id = $_SESSION['user_id'];
$email = $_POST['email'];
$reminder_name = $_POST['reminder_name'];
$reminder_date = $_POST['reminder_date'];
$reminder_amount = $_POST['reminder_amount'];
$add_notes = $_POST['add_notes'];
$conn = new mysqli($host, $muser, $mpass, $db);
$stmt = $conn->prepare("INSERT INTO `reminder` VALUES(?,?,?,?,?,?)");
$stmt->bind_param("ssssss",$user_id, $email, $reminder_name, $reminder_date, $reminder_amount,$add_notes );
$stmt->execute();
$stmt->insert_id;
$stmt->close();
$conn->close();
if ($stmt->execute()) {
?>
<script>
alert('Your reminder has been saved!');
window.setTimeout(function() {
window.location = 'add_reminder.php';
}, 1000);
</script>";
<?php
}
else{
die("Something went wrong");
}
}
?>
</form>
评论