forked from rektoras/project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.php
More file actions
24 lines (20 loc) · 685 Bytes
/
Copy pathadd.php
File metadata and controls
24 lines (20 loc) · 685 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
<?php
$con = mysqli_connect('localhost', 'root', '', 'project');
$added = false;
$newname = '';
$newphone = '';
//check new addition
if(isset($_POST['newname'])){
$newname = $con->real_escape_string($_POST['newname']);
$newphone = $con->real_escape_string($_POST['newphone']);
if($con->query("INSERT INTO contacts (name, phone) VALUES ('$newname', '$newphone')")){
$added = true;
$newid = $con->query("SELECT id FROM contacts WHERE name = '$newname'");
}else{
$added = false;
}
}
$myJSON = array('added' => $added);
echo json_encode($myJSON);
?>
<?php $con->close(); ?>