gpt4 book ai didi

php - 显示和隐藏 php 更新和删除消息?

转载 作者:太空宇宙 更新时间:2023-11-04 09:57:30 26 4
gpt4 key购买 nike

只有在按下提交按钮时,我才能显示更新消息和删除消息,因为每次我打开页面或重新加载页面时,您都可以在不按下提交按钮的情况下看到消息栏

<?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" >
&times;
</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;
}

最佳答案

检查数据是否发送,然后打印msg。

这是代码

<?php
if($_POST){

<div class="alert alert-success">
<button type="button" class="close" >
&times;
</button>
<p><?php echo $msg; ?></p>
</div>
}
?>

关于php - 显示和隐藏 php 更新和删除消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38596943/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com