0% found this document useful (0 votes)
28 views

CRUD PHP

PHP CRUD operation
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

CRUD PHP

PHP CRUD operation
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

PHP CRUD

1. Config.php
a. Create connection
b. Create database
c. Create table
2. <?php
3. $servername="localhost";
4. $username="root";
5. $password="";
6. $dbname="demo_crud";
7.
8. $my_conn=mysqli_connect($servername,$username,$pa
ssword,$dbname);
9.
10. $q= "CREATE TABLE users(ID varchar(10), name
varchar(30), email varchar(30), gender varchar(10))";
11.
12. if(!mysqli_query($my_conn,$q))
13. {
14. echo "Error";
15. }
16. else{
17. echo "table created";
18. }
19. ?>
a.
2. Create (Insert Data)
<?php
include("1.config.php");

if(isset($_POST['submit']))
{
$id=$_POST['ID'];
$name=$_POST['name'];
$email=$_POST['email'];
$gender=$_POST['gender'];

$q= "INSERT INTO `users`(`ID`, `name`,


`email`, `gender`) VALUES
('$id','$name','$email','$gender')";
$result= mysqli_query($my_conn, $q);

if($result)
{
echo "User Added successfully";
}
else{
echo "Failed to add user";
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Document</title>
<style>

table{
width:50%;
}
input[type="text"]{
padding:10px;
width:95%;
}

input[type="radio"]
{
margin:10px;
}
input[type="submit"],input[type="reset"]{
width:150px;
}
td{
text-align:center;
}

input{
text-align:center;
}
</style>
</head>
<body>
<h1 align="center">PHP CRUD Application</h1>

<center><h3 align="center">Add New User</h3></center>

<form action="" method="POST">

<table border="1" cellspacing="0" align="center">


<tr>
<td>ID</td>
<td><input type="text" name="ID"
placeholder="Enter your ID"></td>
</tr>

<tr>
<td>Name</td>
<td><input type="text" name="name"
placeholder="Enter your name"></td>
</tr>

<tr>
<td>Email</td>
<td><input type="text" name="email"
placeholder="example@email.com"></td>
</tr>

<tr>
<td>Gender</td>
<td><input type="radio" name="gender"
value="Male">Male
<input type="radio" name="gender"
value="Female">Female</td>
</tr>

<tr>

<th colspan="2"><input type="submit"


name="submit" value="Add">
<input type="reset"
name="cancel" value="Cancel">
</th></
</tr>
</table>
</form>
</body>
</html>

3. read(show data)

<!DOCTYPE html>
<html lang="en">
<head>
<title>Show data</title>
</head>
<body>
<h1 align="center">PHP CRUD Application</h1>

<h2 align="center">Users</h2>

<center><a href="3.create.php">Add New


User</a></center><br><br>

<table border="1" cellspacing="0" align="center"


width="80%" height="60%">
<tr>
<td bgcolor="purple">ID</td>
<td bgcolor="purple">Name</td>
<td bgcolor="purple">Email</td>
<td bgcolor="purple">Gender</td>
<td bgcolor="purple">Action</td>
</tr>
<?php
include("1.config.php");
$q="SELECT * from `users`";

$result=mysqli_query($my_conn,$q);

while($row=mysqli_fetch_assoc($result)){
?>
<tr>
<td><?php echo $row['ID'] ?></td>
<td><?php echo $row['name']
?></td>
<td><?php echo $row['email']
?></td>
<td><?php echo $row['gender']
?></td>
<td><a
href="edit.php">Edit<a>&nbsp;&nbsp;
<a
href="delete.php">Delete</a></td>
</tr>
<?php
}

?>

</table>
</body>
</html>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy