Admin Page in PHP

<html>
<head>
 <meta charset="UTF-8">
  <meta name="author" content="Muhammad Yasir">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="admin.css">
  <title>Admin</title>
</head>
<body>

<form method="post" action="admin.php">
<table>
<tbody>
<tr>
<td>User Name:</td>
<td><input type="text" name="name" placeholder="Enter your User ID"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" placeholder="Enter your Password"></td>
</tr>
<tr align="right">
<td>
<button type="submit" name="submit" class="btn">LOGIN</button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>


<?php
 include('admin.php');
if(isset($_POST['submit'])){
$name = $_POST['name'];
$password = $_POST['password'];

$querry = "SELECT * FROM login WHERE name='$name' AND password='$password'";
$run = mysqli_query($db,$querry);
$ret=mysqli_num_rows($run);
if($ret == true)
{
echo "<script>window.open('index.php','_self')</script>";
}
else
{
echo "<script>alert('Wrong Login Details, Try Again!')</script>";
}

}


?>



SQL DATABASE

<?php

$db=mysqli_connect('localhost','root','','erp');
?>
CSS FILE
body
{
font-size:19px;
}

table{
width:70%;
margin:30px auto;
border-collapse:collapse;
text-align:left;

}
tr
{
border-bottom:6px solid #cbcbcb;
}
th
{
border:5px;
height:20px;
padding:5px;
}

td
{
border:none;
height:20px;
padding:2px;
}
tr:hover
{
background:#F5F5F5;
}
form
{
width:45%;
margin:50px auto;
text-align:left;
padding:20px;
border:3px solid #bbbbbb;
border-radius:5px;
background-color:yellow;
}




HTML,CSS and PHP Code for Insert, Delete and Update Querris

First file that save in Name of insertdelupdate.php
<?php
 include('server.php');
if(isset($_GET['edit']))
{
$id=$_GET['edit'];
$edit_state=true;
$rec = mysqli_query($db,"SELECT * FROM info where id=$id");
$record=mysqli_fetch_array($rec);
$name=$record['name'];
$address=$record['address'];
$id=$record['id'];

}
 ?>

<html>
<head>
<title>Insert, Update, Delete Demo</title>
<link rel="stylesheet" href="insertdelupadate.css">
</head>
<body>
<?php if(isset($_SESSION['msg'])): ?>
<div class="msg">
<?php
echo $_SESSION['msg'];
unset($_SESSION['msg']);
?>
</div>
<?php endif ?>

<table>
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th colspan="2">Action</th>
</tr>
</thead>
<tbody>
<?php while($row=mysqli_fetch_array($result))
{ ?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><a href="insertdelupdate.php?edit=<?php echo $row['id']; ?> ">Edit</a></td>
<td><a href="server.php?del=<?php echo $row['id'];?>">Delete</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<form method="post" action="server.php">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div class="input-group">
<label>Name</label>
<input type="text" name="name" value="<?php echo $name; ?>">
</div>
<div class="input-group">
<label>Address</label>
<input type="text" name="address" value="<?php echo $address; ?>">
</div>
<div class="input-group">
<?php if($edit_state==false): ?>
<button type="submit" name="save"  class="btn">Save</button>
<?php else: ?>
<button type="submit" name="Update"  class="btn">Update</button>
<?php endif ?>
</div>
</form>
</body>
</html>

Second file save name of server.php

<?php
session_start();
$name="";
$address="";
$id=0;
$edit_state=false;
$db=mysqli_connect('localhost','root','','insertdelupdate');
if(isset($_POST['save']))
{
$name=$_POST['name'];
$address=$_POST['address'];
//insert recod
$query = "INSERT INTO info (name,address) VALUES ('$name','$address')";
mysqli_query($db, $query);
$_SESSION['msg']="Data is Inseted";
header('location:insertdelupdate.php');//redirect to page

}
//update Record
if(isset($_POST['Update']))
{
$name=mysqli_real_escape_string($db,$_POST['name']);
$address=mysqli_real_escape_string($db,$_POST['address']);
$id=mysqli_real_escape_string($db,$_POST['id']);
mysqli_query($db,"UPDATE info SET name='$name',address='$address' WHERE id=$id");
$_SESSION['msg']="Data is updated";
header('location:insertdelupdate.php');//redirect to page

}
//Delete Record
if(isset($_GET['del']))
{
$id=$_GET['del'];
mysqli_query($db,"DELETE FROM info where id=$id");
$_SESSION['msg']="Data is Deleted";
header('location:insertdelupdate.php');

}
//Retrive Record
$result = mysqli_query($db,"SELECT *FROM info");
//redirect to page


?>


css file
body
{
font-size:19px;
}
table{
width:50%;
margin:30px auto;
border-collapse:collapse;
text-align:left;
}
tr
{
border-bottom:1px solid #cbcbcb;
}
th,td
{
border:none;
height:20px;
padding:2px;
}
tr:hover
{
background:#F5F5F5;
}
form
{
width:45%;
margin:50px auto;
text-align:left;
padding:20px;
border:1px solid #bbbbbb;
border-radius:5px;
}
.msg
{
width:45%;
margin:50px auto;
text-align:left;
padding:20px;
border:1px solid #bbbbbb;
border-radius:5px;


}

Inset, Delete and Update in PHP

HTML and PHP Contact Us Page

This is code of Contact Us page in HTML and Php. This code is work online using webhost. You can simply take free domain and apply this code. This code is working Correctly in online domain.
Contact Us Page

<html lang="en-US">
<head>
<link rel="stylesheet" href="style.css">
<meta charset="UTF-8"/>
<title>Login</title>
</head>
<body>
<div id="main">
<div>
<form action="contactus.php" method="post">
<table width="600px" align="center" border="0">
<tr>
<td align="center"colspan="6" bgcolor="red"><h1>Contact Us</h1></td>
</tr>
<tr>
 <td align="right">Enter Your Email:</td>
 <td><input type="text" name="email"></td>
</tr>
<tr>
 <td align="right">Subject:</td>
 <td><input type="text" name="subject"></td>
</tr>
<tr>
 <td align="right">Your Message</td>
 <td><textarea cols="40" rows="10" type="text" name="message"></textarea></td>
</tr>
<tr>
 <td align="center" colspan="6"><input type="submit" name="send_email" value="Send Email"></td>
</tr>
</table>
</form>
</div>
<?php
if(isset($_POST['send_email'])){
$sender_email = $_POST['email'];
$subject= $_POST['subject'];
$mess=$_POST['message'];
$to = "write you mail@gmail.com";
$message= "Email Form".$mess;
if($sender_email=='' or $subject=='' or $mess=='')
{
echo "<script>alert('Please Fil blank Field')</script>";
exit();
}
mail($to,$subject,$message,$sender_email);
$to_sender = $_POST['email'];
$sub = "Thanks for contacting<br>";
$mesg = "Your problem is get sovled soon<br>";
$from = "write you mail@gmail.com";
mail($to_sender,$sub,$mesg,$from);
echo "<center><h2>Email Sent Get you Soon</h2></center>";

}
?>
</div>
</body>
</html>

Total Pageviews