-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.php
More file actions
79 lines (70 loc) · 2.21 KB
/
create.php
File metadata and controls
79 lines (70 loc) · 2.21 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add a new Contact | ContactsBook</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
<style>
body{
width : 75%;
margin: 0 auto;
}
</style>
</head>
<body>
<?php
if($_POST){
include 'config/databaseConnection.php';
try{
//Submitted values being retrieved
$name = htmlspecialchars(strip_tags($_POST['fullname']));
$emailId = htmlspecialchars(strip_tags($_POST['email']));
$mobile = htmlspecialchars(strip_tags($_POST['mobileno']));
$city = htmlspecialchars(strip_tags($_POST['city']));
//Prepare the query
$query = "insert into contacts (`fullname`,`email`,`mobileno`,`city`) values (:fullname,:email,:mobileno,:city)";
$pstmt = $conn->prepare($query);
//Bind the parameter values
$pstmt->bindParam(':fullname',$name,PDO::PARAM_STR);
$pstmt->bindParam(':email',$emailId,PDO::PARAM_STR);
$pstmt->bindParam(':mobileno',$mobile,PDO::PARAM_INT);
$pstmt->bindParam(':city',$city,PDO::PARAM_STR);
if($pstmt->execute()){
echo "<p>Details are Added<br></p>";
}
else{
die("Unable to save the details");
}
}
catch(PDOException $e){
echo "Error : ".$e->getMessage()."<br>";
echo "Line Number : ".$e->getLine()."<br>";
echo "File Name : ".$e->getFile()."<br>";
}
}
?>
<h1>Add a new Address</h1>
<!-- form to enter contact details -->
<form class="pure-form pure-form-stacked" action="create.php" method="POST">
<p>
<label for="fullname">Full Name</label>
<input type="text" name="fullname" id="fullname" required>
</p>
<p>
<label for="email">E-mail</label>
<input type="email" name="email" id="email" required>
</p>
<p>
<label for="mobileno">Mobile Number</label>
<input type="text" name="mobileno" id="mobileno" required>
</p>
<p>
<label for="city">City</label>
<input type="text" name="city" id="city">
</p>
<input class="pure-button pure-button-primary" type="submit" value="Save Details">
</form>
<p><a class="pure-button pure-button-primary" href="read.php">All Contacts</a></p>
</body>
</html>