-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
50 lines (41 loc) · 1.35 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
require './config/db.php';
// //insert data
// $query = "INSERT INTO _user VALUES (DEFAULT , 'VISHAL VAGHASIYA 1' , '[email protected]' ,'".md5('123')."') , (DEFAULT , 'VISHAL VAGHASIYA 2' , '[email protected]' ,'".md5('vish')."')";
// mysqli_query($con , $query);
// if(mysqli_affected_rows($con) > 0){
// $id = mysqli_insert_id($con);
// echo 'User Created with id of :'.$id;
// }else{
// echo mysqli_error($con);
// }
//update
$sql = "UPDATE _user SET username='visha' WHERE _id=2";
if ($con->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $con->error;
}
// sql to delete a record
$sql = "DELETE FROM _user WHERE _id=3";
if ($con->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $con->error;
}
//show database
echo '<table>
<th>Name</th>
<th>Email</th>
';
$query = "SELECT username , email FROM _user";
$result = mysqli_query($con , $query);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
echo '<tr><td>'.$row['username'].'</td><td>'.$row['email'].'</td></tr>';
}
}else{
echo mysqli_error($con);
}
echo '</table>';
?>