how can i show update message and delete message only if i pressed the submit button because every time when i open the page or reload it you can see the message bar without me pressing the submit button
<?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>
my css code for alerts
.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;
}
Check whether the data is posted and then print the msg.
Here is the code
<?php
if($_POST){
<div class="alert alert-success">
<button type="button" class="close" >
×
</button>
<p><?php echo $msg; ?></p>
</div>
}
?>
<div class="alert alert-success <?=isset($_POST['update']) ? '' : 'hidden' ?>">
<button type="button" class="close" >
×
</button>
<p><?php echo $msg; ?></p>
</div>
This will apply the hidden
css class to your alert box if there has been no post call. This looks like bootstrap, so the class should already be defined.
The snippet is untested, but it should give you a general idea.