-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.php
65 lines (43 loc) · 1.38 KB
/
update.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
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
$database = "demo";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$myFile = "/xampp/htdocs/guvi/data.json";
$arr_data = array(); // create empty array
$email = $_POST["email"];
$name = $_POST["name"];
$age = $_POST["age"];
$gender = $_POST["gender"];
$phone = $_POST["phone"];
$dob = $_POST["dob"];
$college = $_POST["college"];
$state = $_POST["state"];
$degree = $_POST["degree"];
$dept = $_POST["dept"];
$yop = $_POST["yop"];
$aoi = $_POST["aoi"];
// prepare and bind
$sql = $conn->prepare("UPDATE User SET name=?, age=?, gender=?, phone=?, dob=?, college=?, state=?, degree=?, department=?, yop=?, aoi=? WHERE email=?");
$sql->bind_param("ssssssssssss", $name, $age, $gender, $phone, $dob, $college, $state, $degree, $dept, $yop, $aoi, $email);
$sql->execute();
$result = $conn->query("SELECT * FROM User");
$count = $result->num_rows;
//Initialize array variable
$dbdata = array();
console.log("Message here");
//Fetch into associative array
while ($row = $result->fetch_assoc()) {
$dbdata[] = $row;
}
$jsondata = json_encode($dbdata, JSON_PRETTY_PRINT);
echo $jsondata;
file_put_contents($myFile, $jsondata);
echo "2";
?>