Skip to content

Commit 188fb8e

Browse files
committed
Class 12 added & php crud edit part done
1 parent bb04ca2 commit 188fb8e

38 files changed

+228
-0
lines changed
Binary file not shown.
Binary file not shown.
6 Bytes
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
$conn = mysqli_connect('localhost','root','','skit_crud');
4+
5+
if(!$conn)
6+
{
7+
die('Database connection failed').mysqli_connect_error();
8+
}
9+
// Print host information
10+
//echo "Connect Successfully. Host info: " . mysqli_get_host_info($conn);
11+
?>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
include "connection.php";
3+
?>
4+
<!DOCTYPE html>
5+
<html lang="en">
6+
<head>
7+
<meta charset="UTF-8">
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
9+
<title>php crud</title>
10+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
11+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css">
12+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.css">
13+
</head>
14+
<body>
15+
16+
<?php
17+
include "connection.php";
18+
$error="";
19+
if (isset($_POST['submit'])) {
20+
21+
$name = $_POST['name'];
22+
$email = $_POST['email'];
23+
$mobile = $_POST['mobile'];
24+
$address = $_POST['address'];
25+
if(empty($name) || empty($email) || empty($mobile) || empty($address))
26+
{
27+
$error ="All field are required";
28+
}
29+
else{
30+
31+
$insert = "INSERT INTO users(name,email,mobile,address)VALUES('$name','$email','$mobile','$address')";
32+
$result = mysqli_query($conn,$insert);
33+
if ($result) {
34+
header("location:index.php?msg=".urlencode('User information save seccessfully'));
35+
}else{
36+
echo "Data insert failed";
37+
}
38+
39+
}
40+
}
41+
42+
?>
43+
44+
<div class="container">
45+
<h1>PHP CRUD</h1>
46+
<hr>
47+
<a href="index.php" class="button button-outline">Back</a>
48+
49+
<p style="color:red"> <?php echo $error??"";?> </p>
50+
51+
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'])?>" method="post">
52+
<fieldset>
53+
<label for="nameField">Name</label>
54+
<input type="text" name="name" placeholder="Name" id="nameField">
55+
56+
<label for="emailField">Email</label>
57+
<input type="email" name="email" placeholder="Email" id="emailField">
58+
59+
<label for="mobile">Mobile</label>
60+
<input type="text" name="mobile" placeholder="Mobile number" id="mobile">
61+
62+
<label for="address">Address</label>
63+
<textarea name="address" placeholder="Enter address" id="address"></textarea>
64+
65+
<input class="button-primary" type="submit" name="submit" value="Submit">
66+
</fieldset>
67+
</form>
68+
69+
</div>
70+
</body>
71+
</html>

Class-12-10-09-2020/php-crud/edit.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
include "connection.php";
3+
?>
4+
<!DOCTYPE html>
5+
<html lang="en">
6+
<head>
7+
<meta charset="UTF-8">
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
9+
<title>php crud</title>
10+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
11+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css">
12+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.css">
13+
</head>
14+
<body>
15+
16+
<?php
17+
include "connection.php";
18+
$error = "";
19+
if (isset($_POST['submit'])) {
20+
21+
$name = $_POST['name'];
22+
$email = $_POST['email'];
23+
$mobile = $_POST['mobile'];
24+
$address = $_POST['address'];
25+
$id = $_POST['id'];
26+
27+
if (empty($name) || empty($email) || empty($mobile) || empty($address)) {
28+
$error = "All field are required";
29+
} else {
30+
31+
$insert = "Update users SET name='$name',email='$email', mobile='$mobile',address='$address' WHERE id='$id'";
32+
$result = mysqli_query($conn, $insert);
33+
if ($result) {
34+
header("location:index.php?msg=" . urlencode('User information update seccessfully'));
35+
} else {
36+
echo "Data insert failed";
37+
}
38+
39+
}
40+
} else {
41+
if (isset($_GET['id']) && $_GET['id'] != null) {
42+
43+
$id = $_GET['id'];
44+
45+
$select = "SELECT * FROM users WHERE id='$id' LIMIT 1";
46+
$result = mysqli_query($conn, $select);
47+
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
48+
49+
}
50+
}
51+
52+
?>
53+
54+
<div class="container">
55+
<h1>PHP CRUD</h1>
56+
<hr>
57+
<a href="index.php" class="button button-outline">Back</a>
58+
59+
<p style="color:red"> <?php echo $error ?? ""; ?> </p>
60+
61+
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
62+
<fieldset>
63+
<label for="nameField">Name</label>
64+
<input type="text" name="name" placeholder="Name" value="<?php echo $row['name'] ?? ''; ?>" id="nameField">
65+
66+
<label for="emailField">Email</label>
67+
<input type="email" name="email" placeholder="Email"value="<?php echo $row['email'] ?? ''; ?>" id="emailField">
68+
69+
<label for="mobile">Mobile</label>
70+
<input type="text" name="mobile" placeholder="Mobile number"value="<?php echo $row['mobile'] ?? ''; ?>" id="mobile">
71+
72+
<label for="address">Address</label>
73+
<textarea name="address" placeholder="Enter address" id="address"><?php echo $row['address'] ?? ''; ?>
74+
</textarea>
75+
76+
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
77+
78+
<input class="button-primary" type="submit" name="submit" value="Update">
79+
</fieldset>
80+
</form>
81+
82+
</div>
83+
</body>
84+
</html>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
include "connection.php";
3+
?>
4+
<!DOCTYPE html>
5+
<html lang="en">
6+
<head>
7+
<meta charset="UTF-8">
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
9+
<title>php crud</title>
10+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
11+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css">
12+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.css">
13+
</head>
14+
<body>
15+
16+
<div class="container">
17+
<h1>PHP CRUD</h1>
18+
<hr>
19+
<a href="create.php" class="button">Add New</a>
20+
<br>
21+
<h3 style="color:green">
22+
<?php
23+
if (isset($_GET['msg'])) {
24+
echo $_GET['msg'];
25+
}
26+
?>
27+
</h3>
28+
<table>
29+
<tr>
30+
<th>S/N</th>
31+
<th>Name</th>
32+
<th>Email</th>
33+
<th>Mobile</th>
34+
<th>Address</th>
35+
<th>Action</th>
36+
</tr>
37+
<?php
38+
39+
$slq = "SELECT * FROM users";
40+
$result = mysqli_query($conn, $slq);
41+
if ($result) {
42+
while ($row = mysqli_fetch_assoc($result)) {?>
43+
<tr>
44+
<td><?php echo $row['id']; ?></td>
45+
<td><?php echo $row['name']; ?></td>
46+
<td><?php echo $row['email']; ?></td>
47+
<td><?php echo $row['mobile']; ?></td>
48+
<td><?php echo $row['address']; ?></td>
49+
<td>
50+
<a href="edit.php?id=<?php echo $row['id']; ?>" class="button">Edit</a>
51+
<a href="" class="button button-outline">Delete</a>
52+
</td>
53+
</tr>
54+
<?php
55+
}
56+
}
57+
58+
?>
59+
</table>
60+
</div>
61+
</body>
62+
</html>

0 commit comments

Comments
 (0)