Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions api/passenger/update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
$conn=mysqli_connect("localhost","root","");
$db=mysqli_db("cmsc_team_alpha");


$url = 'php://input'; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$vals = json_decode($data); // decode the JSON feed

if(is_null($vals))
{
header('HTTP/1.1 400 Bad Request');
echo json_encode(array('message' => 'No contents to process'));

}
else{
$id=$vals->id
$firstname=$vals->firstname;
$lastname=$vals->lastname;
$email=$vals->email;
$password=$vals->password;
$address=$vals->address;
$mobile=$vals->mobile;
$pmobile=$vals->panicmobile;
$datemodified=date("Y-m-d H:i:s");

$checkexisting=mysqli_query($conn, "SELECT email,mobile,panicmobile FROM tbl_rider WHERE email LIKE '$email'
|| email LIKE '$mobile' || panicmobile LIKE '$pmobile'");
if(mysqli_num_rows($checkexisting)>0)
{
header('HTTP/1.1 400 Bad Request');
echo json_encode(array('message' => 'Email Or mobile used is currently registered try using another.'));
}
else{

if(count(json_decode($data,1))==0) {
header('HTTP/1.1 400 Bad Request');
echo json_encode(array('message' => 'Passenger details are empty.'));
}
else{
//Insert Query
$qrys=mysqli_query($conn, "UPDATE passenger SET firstname = $firstname, lastname = $lastname,
email = $email,password = $password,address = $address,mobile = $mobile,
panicmobile = $pmobile,datemodified = $datemodified WHERE id = $id");

if($qrys)
{
header('HTTP/1.1 400 Bad Request');
echo json_encode(array('message' => 'Query Error'));

}
else
{
header('HTTP/1.1 201 Created');
echo json_encode(array('message' => 'Successfully updated the record', 'passengerId' => $id));
}
}
}
}

?>