Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在mysqli prepare中提交表单后显示成功消息_Php_Html_Mysql - Fatal编程技术网

Php 在mysqli prepare中提交表单后显示成功消息

Php 在mysqli prepare中提交表单后显示成功消息,php,html,mysql,Php,Html,Mysql,记录插入成功后如何显示成功消息。此代码工作正常,但不显示任何消息 error_reporting(E_ALL ^ E_NOTICE); $name=$_POST['name']; $email=$_POST['email']; $massage=$_POST['massage']; $organization=$_POST['organization']; $stmt = mysqli_prepare($connection, "INSERT INTO massage_board(name,e

记录插入成功后如何显示成功消息。此代码工作正常,但不显示任何消息

error_reporting(E_ALL ^ E_NOTICE);
$name=$_POST['name'];
$email=$_POST['email'];
$massage=$_POST['massage'];
$organization=$_POST['organization'];

$stmt = mysqli_prepare($connection, "INSERT INTO massage_board(name,email,organization,massage)VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'ssss', $name, $email, $organization, $massage);

/* execute prepared statement */
mysqli_stmt_execute($stmt);
if($stmt->execute()){
    echo "<div id=\"success\"><h2>Your message has been sent. Thank you!</h2></div>";

header('Location:contact.html');
}else{
echo "Please retry";    
}
错误报告(E\u所有^E\u通知);
$name=$_POST['name'];
$email=$_POST['email'];
$按摩=$_POST[“按摩”];
$organization=$_POST['organization'];
$stmt=mysqli_prepare($connection,“插入按摩板(名称、电子邮件、组织、按摩)值(?,,?)”;
mysqli_stmt_bind_param($stmt,$ssss',$name,$email,$organization,$按摩);
/*执行准备好的语句*/
mysqli_stmt_execute($stmt);
如果($stmt->execute()){
echo“您的邮件已发送,谢谢!”;
标题('Location:contact.html');
}否则{
回显“请重试”;
}

您的消息会显示出来,但它会重定向到另一个页面,这样您就看不到它了。请尝试在页面上不重定向的情况下执行以下代码

if($stmt->execute()){
    echo "<div id=\"success\"><h2>Your message has been sent. Thank you!</h2></div>";

header('Location:contact.html');   <--- Remove this line
}
if($stmt->execute()){
echo“您的邮件已发送,谢谢!”;

标题('Location:contact.html');在显示消息后立即转到
contact.html
,因此您无法看到消息:) 您应该通过Javascript来实现这一点

echo "<div id=\"success\"><h2>Your message has been sent. Thank you!</h2></div>";
echo "<script>setTimeout(\"location.href = 'http://www.example.com/contact.html';\",1500);</script>";
echo“您的邮件已发送,谢谢!”;
echo“setTimeout(\”location.href='1http://www.example.com/contact.html';\",1500);";
更新: 试试这个:

$stmt = mysqli_prepare($connection, "INSERT INTO massage_board(name,email,organization,massage)VALUES (?, ?, ?, ?)");
$stmt->bind_param('ssss', $name, $email, $organization, $massage);

if($stmt->execute()){
    echo "<div id=\"success\"><h2>Your message has been sent. Thank you!</h2></div>";

echo "<script>setTimeout(\"location.href = 'http://www.example.com/contact.html';\",1500);</script>";
}else{
echo "Please retry";    
}
$stmt=mysqli_prepare($connection,“插入按摩板(名称、电子邮件、组织、按摩)值(?,,?)”;
$stmt->bind_param('ssss',$name,$email,$organization,$按摩);
如果($stmt->execute()){
echo“您的邮件已发送,谢谢!”;
echo“setTimeout(\”location.href='1http://www.example.com/contact.html';\",1500);";
}否则{
回显“请重试”;
}

您是否有删除
标题(“位置:contact.html”)的解决方案
当你删除标题时,你会得到什么?你的意思是成功插入记录,但没有显示任何内容?你有javascript或jquery用于隐藏和显示div吗?你的意思是删除所有内容吗?你要删除什么?但它没有显示我删除标题重定向的消息。我已经测试过,工作正常。只需更换
标题即可('Location:contact.html');
with
echo“setTimeout(\”Location.href='class1)http://www.example.com/contact.html“;\”,1500);“
等等……你是什么意思
mysqli\u stmt\u execute($stmt);if($stmt->execute()){}
?试试这个:
$stmt=mysqli\u prepare(…);$stmt->bind\u param(…)if($stmt->execute()){}
谢谢您的帮助,但标题效果很好,所以我选择使用javascript。我的问题是表单没有显示成功消息。它会重定向到我希望的任何地址。我知道,但如果您使用标题,它会立即重定向到其他页面,因此您无法看到成功消息,您的应用程序必须在显示成功消息后暂停一段时间然后重定向ss消息。因此,您需要使用Javascript和
setTimeout
函数,以确保在重定向之前的一段时间内显示成功消息