-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbinsert.php
More file actions
62 lines (56 loc) · 1.4 KB
/
dbinsert.php
File metadata and controls
62 lines (56 loc) · 1.4 KB
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
<?php
// 1- connect to db
$host="127.0.0.1";
$user="root";
$password="12345";
$database="admins";
$connect= mysqli_connect($host, $user, $password, $database);
if(mysqli_connect_errno()){
die("cannot connect to database field:". mysqli_connect_error());
}
else {
echo 'Database is connected';
}
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
//2- insert from database
// button click
if (isset($_POST['submit'])) {
$usename=$_POST['username'];
$password=$_POST['password'];
$query="insert into logins (username,password)values('". $usename . "','". $password . "')";
$result= mysqli_query($connect, $query);
if( $result){
echo '</br>Data is inerted';
}
else {
die("Database query failed. " . mysqli_error($connection));
}
}
?>
<form action='' method='POST'>
User Name:<input type='text' name='username'>
</br>
Password:<input type='password' name='password'>
</br>
<input type='submit' name='submit' value='insert'>
</form>
<a href="dbread.php">View Data</a>
</body>
</html>
<?php
//5 close connection
mysqli_close($connect);
?>