-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertCode.php
More file actions
31 lines (25 loc) · 1017 Bytes
/
InsertCode.php
File metadata and controls
31 lines (25 loc) · 1017 Bytes
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
<?php
//create a variable and connect it to mysqli using localhost, your username and password
$connection = mysqli_connect("localhost","root","");
//calling DB with connection and and my DB name
$db = mysqli_select_db($connection, 'address-book');
if(isset($_POST['insertdata'])) //if I click the button(Save Data)
{
$name = $_POST['name'];
$contact = $_POST['contact'];
$address = $_POST['address'];
$dob = $_POST['dob']; //calling all the fields from the form
//giving a query
$query = "INSERT INTO `address-book` (`name`, `contact`, `address`, `dob`) VALUES ('$name', '$contact', '$address', '$dob')";
$query_run = mysqli_query($connection, $query); //running the query
if($query_run) //it the query is running then Data Saved
{
echo '<script> alert("Data Saved"); </script>';
header('Location: index.php');
}
else //else Data Not saved
{
echo '<script> alert("Data Not Saved"); </script>';
}
}
?>