如何在绿色显示警报消息一段时间或在插入数据库后在右侧显示关闭按钮。
<?php
include('../session.php');
$from="$session_id";
$to=mysql_real_escape_string($_POST["to"]);
$subject=mysql_real_escape_string($_POST["ssubject"]);
$message=mysql_real_escape_string($_POST["smessage"]);
if($from==$to){
echo "Message could not be sent";
die();
}
if($from>1 && $to>1){
echo "Message could not be sent";
die();
}
//echo $to.$message;
//validate before insert
if(strlen($subject)>50){
echo "Subject was too long";
die();
}
if(strlen($message)>150){
echo "Message was too long";
die();
}
include('../dbsource.php');
$mysqli=connect();
if(insert($mysqli,$from,$to,$subject,$message)>0)
{
// echo "<script type=\"text/javascript\">".
// "alert('Message was successfully sent');".
//"</script>";
$result='successfully sent message';
}
else
{
echo "<script type=\"text/javascript\">".
"alert('there was error sending message.. please try it later');".
"</script>";
}
?>
<?php
function insert($mysqli,$from,$to,$subject,$message){
$mdate=date('Y-m-d');
$mtime=date('H:i:s');
$query = "INSERT INTO messages (mfrom,mto,subject,message,mdate,mtime)".
"VALUES ('$from','$to','$subject','$message','$mdate','$mtime')";
if($mysqli->query($query)>0)
return($mysqli->insert_id);
else
return 0;
}
并且php页面包含以下代码:
<div class="alert alert-success fade in">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Success!</strong><? $result ?>
</div>
如何在bootstrap警告框中显示成功的消息?
答案 0 :(得分:0)
我知道这个答案很晚,但是我想也许像我这样的人想要一个答案
我有2个要处理的功能(插入数据库)
<?php
$nameErr = "";
$familyErr = "";
$codeErr = "";
$passErr = "";
function create_student($name, $family, $code, $pass)
{
global $conn, $tbl_student;
$sql = "INSERT INTO $tbl_student (students_code, students_pass, students_name, students_family) VALUES (? ,? ,?,?)";
$create_student = $conn->prepare($sql);
$create_student->bindParam(1, $code);
$create_student->bindParam(2, $pass);
$create_student->bindParam(3, $name);
$create_student->bindParam(4, $family);
$create_student->execute();
$student=$name." ".$family;
if($create_student->rowCount()>=1){
$result_create_student=['1',$student];
}
else
{
$result_create_student=['0',"error in inserting"];
}
return $result_create_student;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_POST['submit-create-student']) && ($_SERVER['REQUEST_METHOD'] == 'POST')) {
if (empty($_POST["student-name"])) {
$nameErr = "you must insert name.";
} else {
$name = sanitize_func($_POST["student-name"]);
}
if (empty($_POST["student-family"])) {
$familyErr = "you must insert family.";
} else {
$family = sanitize_func($_POST["student-family"]);
}
if (empty($_POST["student-code"])) {
$codeErr = "you must insert code.";
} else {
$code = sanitize_func($_POST["student-code"]);
}
if (empty($_POST["student-pass"])) {
$passErr = "you must insert pass.";
} else {
$pass = sanitize_func($_POST["student-pass"]);
}
if (($nameErr == "") && ($familyErr == "") && ($codeErr == "") && ($passErr == "")) {
$result_create_student=create_student($name, $family, $code,$pass);
}
}
?>
我们想要在我的代码中显示结果的部分我确实如此
<div class="px-2 text-right schms-font-size-12 mb-1">
<?php if (isset($result_create_student) && $result_create_student != "") : ?>
<?php if ($result_create_student[0] == '1'): ?>
<div class="alert alert-success alert-dismissible text-right">
<button type="button" class="close" data-dismiss="alert">×
</button>
<strong class="pl-1">success!</strong>
one student with name
<span class="text-justify"><?php echo $result_create_student[1]; ?></span>
inserting in databse.
</div>
<?php elseif ($result_create_student[0] == '0'): ?>
<div class="alert alert-danger alert-dismissible text-right">
<button type="button" class="close" data-dismiss="alert">×
</button>
<strong class="pl-1">error!</strong>
<span class="text-justify"><?php echo $result_create_student[1]; ?></span>
</div>
<?php endif; ?>
<?php endif; ?>
我希望它有用