-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_phone.php
45 lines (35 loc) · 1.28 KB
/
update_phone.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
<?php
include('header.php');
include('dbcon.php');
$row = array();
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query = "SELECT * FROM phones WHERE phoneID = '$id'";
$result = mysqli_query($connection, $query);
if (!$result) {
die("Query Failed: " . mysqli_error($connection));
} else {
$row = mysqli_fetch_assoc($result);
}
}
if (isset($_POST['update_phones'])) {
$phoneid = $_GET['id']; // Get the phone ID from the URL
$phonenumber = $_POST['phonenumber'];
$query = "UPDATE phones SET phoneNumber = '$phonenumber' WHERE phoneID = '$phoneid'";
$result = mysqli_query($connection, $query);
if (!$result) {
die("Query failed: " . mysqli_error($connection));
} else {
header('location:index.php?update_msg=You have successfully updated the data.');
exit();
}
}
?>
<form action="update_phone.php?id=<?php echo $id; ?>" method="post">
<div class="form-group">
<label for="phonenumber">Phone Number</label>
<input type="text" name="phonenumber" class="form-control" value="<?php echo isset($row['phoneNumber']) ? $row['phoneNumber'] : ''; ?>">
</div>
<input type="submit" class="btn btn-success" name="update_phones" value="UPDATE">
</form>
<?php include('footer.php'); ?>