-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase2.php
80 lines (52 loc) · 1.5 KB
/
database2.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
$dbconnet = [
'host' => 'localhost',
'username' => 'root',
'password' => '123456',
'dbname' => 'php_work'
];
$conn = new mysqli( $dbconnet['host'],$dbconnet['username'],$dbconnet['password'],$dbconnet['dbname']);
if( $conn->connect_errno ){
echo 'Database connect error';
}
$id =3;
// $sql = "update user set lastname='alex',email='[email protected]' where id=7";
$sql = "select * from user";
$result = $conn->query($sql);
// if( $result->fetch_assoc() >= 0 ){
while($raw = $result->fetch_assoc()){
echo 'Name : '. $raw['firstname'].' '.$raw['lastname'].'<br>';
}
// } else{
// echo 'have no data';
// }
if(isset($_POST['btn'])){
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$email = $_POST['email'];
$inser = "INSERT INTO user(firstname,lastname,email) value('$fname','$lname','$email')";
if($conn->query($inser) == true){
echo 'create';
header('location:database2.php');
} else {
echo 'error';
}
}
// var_dump( $_SERVER );
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="database2.php" method="post">
<input type="text" name="firstname"> <br>
<input type="text" name="lastname"> <br>
<input type="text" name="email"> <br>
<button type="submit" name="btn">save</button>
</form>
</body>
</html>