FORM INSERT SELECT AND DELETE
1. Form.php
<form action="insert.php" method="post" enctype="multipart/form-data">
<p>First Name:<input type="text" name="first" placeholder="First Name">
Last Name:<input type="text" name="last" placeholder="Last Name"></p>
<p>Email:<input type="email" name="email" placeholder="Email">
Mobile:<input type="tele" name="mobile" placeholder="Mobile"></p>
<p>
Gender:
Male<input type="radio" name="gender" value="Male" >
Female<input type="radio" name="gender" value="Female" >
</p>
<p>Hobbies:
Singing <input type="checkbox" name="hobbies[]" value="Singing">
Dancing <input type="checkbox" name="hobbies[]" value="Dancing">
Art <input type="checkbox" name="hobbies[]" value="Art">
cricket <input type="checkbox" name="hobbies[]" value="Cricket"><br>
</p>
<p>
<textarea name="Message" rows="5" cols="40" placeholder="Enter Message">
</textarea>
<!__<input type ="file" name="upload"><!__<br>
<input type="submit" name="submit" value="Submit" >
</p>
<br><a href="select.php" type="submit" name="logout">Show</a>
</form>
2. db.php
<?php
$servername="localhost";
$username="root";
$password="123456789";
$db_name="database_name";//your database Name
$connection=mysqli_connect($servername,$username,$password,$db_name);
// Check connection
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
//echo "Connected successfully";
?>
3. insert.php
<?php
require "db.php";//for database connection
if (isset($_POST['submit'])){ $first=$_POST['first'];
$last=$_POST['last'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$gender=$_POST['gender'];
$hobbies=$_POST['hobbies'];
$arr=implode(",",$hobbies);
$message=$_POST['Message'];
//******************************INSERT QUERY START HERE******************************
$query="INSERT INTO forms(first_name,last_name,email,mobile,gender,hobbies,message)
VALUES('$first','$last','$email','$mobile','$gender','$arr','$message')";
$insert=mysqli_query($connection,$query);
if (!$insert==0){
echo "Record inserted Successfully";
}
else
{
echo "validations Failed";
}
}
?>
4. select.php
<table align="center" >
<table style="width:900px;"border="5" >
<tr><th colspan="9"><h1>Records</h1></th></tr>
<tr align="center">
<td><h3>ID</h3></td>
<td><h3>FIRST NAME</h3></td>
<td><h3>LAST NAME</h3></td>
<td><h3>EMAIL</h3></td>
<td><h3>MOBILE</h3></td>
<td><h3>GENDER</h3></td>
<td><h3>HOBBIES</h3></td>
<td><h3>MESSAGE</h3></td>
<td><h3>ACTION</h3></td>
</tr>
<?php
//require "db.php";
//if(isset($_POST['submit'])){
include('db.php');
$select= "SELECT * FROM forms";
$result = mysqli_query($connection,$select);
while($row = mysqli_fetch_array($result)){
?> <tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['first_name'];?></td>
<td><?php echo $row['last_name'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['mobile'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['hobbies'];?></td>
<td><?php echo $row['message'];?></td>
<td><a href='delete.php?id=<?php echo $row['id']; ?>'>Delete</a></td>
</tr> <?php } ?>
</table>
5. delete.php
<table align="center" >
<table style="width:900px;"border="5" >
<tr><th colspan="9"><h1>Records</h1></th></tr>
<tr align="center">
<td><h3>ID</h3></td>
<td><h3>FIRST NAME</h3></td>
<td><h3>LAST NAME</h3></td>
<td><h3>EMAIL</h3></td>
<td><h3>MOBILE</h3></td>
<td><h3>GENDER</h3></td>
<td><h3>HOBBIES</h3></td>
<td><h3>MESSAGE</h3></td>
<td><h3>ACTION</h3></td>
</tr>
<?php
//require "db.php";
//if(isset($_POST['submit'])){
include('db.php');
$select= "SELECT * FROM forms";
$result = mysqli_query($connection,$select);
while($row = mysqli_fetch_array($result)){
?> <tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['first_name'];?></td>
<td><?php echo $row['last_name'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['mobile'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['hobbies'];?></td>
<td><?php echo $row['message'];?></td>
<td><a href='delete.php?id=<?php echo $row['id']; ?>'>Delete</a></td>
</tr> <?php } ?>
</table>
No comments:
Post a Comment