如何使用引导类警报显示成功消息 PHP 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32516803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:02:07 来源:igfitidea点击:
How to display success message PHP code with bootstrap class alert
提问by Nisha Chinnapa
I need to display Success Message while update or insert records in using PHP
我需要在使用 PHP 更新或插入记录时显示成功消息
this is my HTML code
这是我的 HTML 代码
<form action='a.php' methord='post'>
// alert message here
<div class="alert">
<a class="close" data-dismiss="alert"><i class="icon-remove"></i></a>
<strong><?php echo $message; ?></strong>
</div>
<input type="text" class="form-control" style="height:27px;" name="name"\>
<input type="email" class="form-control" style="height:27px;" name="email"\>
<input type="tel" class="form-control" style="height:27px;" name="mobile"\>
<input type="submit" name="user_details" class="btn btn-danger" value="Submit" />
</form>
Php Code (a.php):
PHP代码(a.php):
if(isset($_POST['user_details']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$mobile= $_POST['mobile'];
$sql = mysql_query("update user_details set name='$name', email='$email', mobile='$mobile'");
if($sql==true)
{
$message = 'Success';
}
else
{
echo ''.mysql_error();
}
}
回答by Neeraj Kumar
HTML
HTML
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
PHP
PHP
if ($error == false) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
}else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
回答by Insane Skull
Try like this:
像这样尝试:
echo '<div class="alert alert-success alert-dismissable" id="flash-msg">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<h4><i class="icon fa fa-check"></i>Success!</h4>
</div>';
And if you want auto dismiss alert then use jquery:
如果您想自动关闭警报,请使用 jquery:
$(document).ready(function () {
$("#flash-msg").delay(3000).fadeOut("slow");
});
回答by aldrin27
Try this:
尝试这个:
if($sql==true)
{
$message = '<div class="alert alert-success" role="alert">Success</div>';
}
else
{
echo ''.mysql_error();
}