如果我按下提交按钮,我怎么能显示更新消息和删除消息,因为每当我打开页面或重新加载它时,你都可以看到消息栏,而我没有按下提交按钮
<?php require_once("header.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="RTL" lang="Ar">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<?php
if(isset($_GET['language_id']) && is_numeric($_GET['language_id']) && $_GET['language_id'] > 0 ){
$language_id = $_GET['language_id'];
}
?>
<?php include ("connection.php"); ?>
<?php
$msg = "";
if (isset($_POST['update'])) {
if(is_numeric($_POST['language_id'])){
$language_id = mysqli_real_escape_string($link,htmlspecialchars($_POST['language_id']));
$language_name = mysqli_real_escape_string($link,htmlspecialchars($_POST['language_name']));
if ($language_name == "")
{
$msg = "يرجى تعبيئة كافة الحقول" ;
}
else
{
$sql = mysqli_query ($link,"UPDATE `programming_language` SET `language_name`='".$language_name."'
WHERE `language_id`='".$language_id."' ");
if($sql){
$msg = "تمت عملية التعديل بنجاح";
// header ("location:edit_programming_language.php");
}
}
}
else
{
echo "Error !";
}
}
else
{
if(isset($_GET['language_id']) && is_numeric($_GET['language_id']) && $_GET['language_id'] > 0 ){
$language_id = $_GET['language_id'];
$query = mysqli_query($link,"SELECT * FROM `programming_language` WHERE `language_id` ='".$language_id."' ") or die(mysqli_error($link));
while( $row = mysqli_fetch_assoc ($query) ){
$language_id = $row ['language_id'];
$language_name = $row['language_name'];
}
}
}
?>
<div class="page-container">
<div class="alert alert-success">
<button type="button" class="close" >
×
</button>
<p><?php echo $msg; ?></p>
</div>
<div class="edit-programming-language">
<form method= "POST" action = "" >
<input type="hidden" name = "language_id" value="<?php echo $language_id ;?>" />
<p>
<label>اسم اللغة</label>
<td><input type="text" name = "language_name" value="<?php echo $language_name ;?>" /></td>
</p>
<p>
<td><input type="submit" name = "update" class="button edit-programming-language-btn" value="تحديث البيانات" /></td>
</p>
<input type="hidden" name = "examinee_id" value="<?php echo $_GET['language_id']; ?>" />
</form>
</div>
</div>
</body>
</html>
我的警报css代码
.alert {
padding: 15px;
margin-bottom: 20px;
height:25px;
border: 1px solid transparent;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
display: block;
}
.alert-success {
color: #3c763d;
background-color: #dff0d8;
border-color: #d6e9c6;
border-top-color: #c9e2b3;
}
.alert-danger {
color: #a94442;
background-color: #f2dede;
border-color: #ebccd1;
border-top-color: #e4b9c0;
}
.alert p {
text-align: center;
font-size:20px;
line-height:25px;
margin-bottom: 5px;
margin-top: 0px;
}
答案 0 :(得分:1)
检查数据是否已过帐,然后打印信息。
这是代码
<?php
if($_POST){
<div class="alert alert-success">
<button type="button" class="close" >
×
</button>
<p><?php echo $msg; ?></p>
</div>
}
?>
答案 1 :(得分:0)
<div class="alert alert-success <?=isset($_POST['update']) ? '' : 'hidden' ?>">
<button type="button" class="close" >
×
</button>
<p><?php echo $msg; ?></p>
</div>
如果没有帖子通话,这会将hidden
css类应用于您的提示框。这看起来像bootstrap,因此应该已经定义了类。
该代码段尚未经过测试,但它应该为您提供一般概念。