Google
Edit File: update.php
<?php include "db.php"; header('Content-Type: application/json'); // Allow only POST if($_SERVER['REQUEST_METHOD'] !== 'POST'){ http_response_code(405); echo json_encode(["status"=>"error","message"=>"Method not allowed"]); exit; } // Validate fields $required = ['id','name','email','phone']; foreach($required as $field){ if(empty($_POST[$field])){ http_response_code(400); echo json_encode(["status"=>"error","message"=>"Missing field: $field"]); exit; } } $id = (int)$_POST['id']; $name = trim($_POST['name']); $email = trim($_POST['email']); $phone = trim($_POST['phone']); $subject = trim($_POST['subject']); $message = trim($_POST['message']); // Validate email if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ echo json_encode([ "status"=>"error", "message"=>"Invalid email format" ]); exit; } // Check row exists $check = $conn->prepare("SELECT id FROM contact_enquiries WHERE id=?"); $check->bind_param("i",$id); $check->execute(); if($check->get_result()->num_rows === 0){ echo json_encode([ "status"=>"error", "message"=>"Record not found" ]); exit; } // Update $stmt = $conn->prepare(" UPDATE contact_enquiries SET name=?, email=?, phone=?, subject=?, message=? WHERE id=? "); $stmt->bind_param("sssssi", $name,$email,$phone,$subject,$message,$id); $stmt->execute(); if($stmt->affected_rows > 0){ echo json_encode([ "status"=>"success", "message"=>"Enquiry updated successfully!" ]); }else{ echo json_encode([ "status"=>"nochange", "message"=>"No changes detected." ]); }