So I've been stuck for a few hours trying to compare $_SESSION data stored as a variable with $_POST data from updated form fields but when I use array array_diff_assoc or array_diff i get either the whole session data array or the whole post data array(depending oh how I order them in the array function), and not the difference. I want to be able to output the difference only.
<?php
if(isset($_SESSION['username'])) {
$username = $_SESSION['username'];
$query = "SELECT * FROM updatetest WHERE username = '{$username}' ";
$select_users= mysqli_query($db, $query);
while ($row = mysqli_fetch_array($select_users)) {
$user_info['name'] = $row['name'];
$user_info['phone'] = $row['phone'];
$user_info['dob'] = $row['dob'];
$user_info['email'] = $row['email'];
$user_info['address_line_1'] = $row['address_line_1'];
$user_info['town_city'] = $row['town_city'];
$user_info['postcode'] = $row['postcode'];
$your_data[]=$user_info;
}
}
?>
<?php
if(isset($_POST['submit'])) {
$name= $_POST['name'];
$phone = $_POST['phone'];
$dob = $_POST['dob'];
$email = $_POST['email'];
$address_line_1 = $_POST['address_line_1'];
$town_city = $_POST['town_city'];
$postcode = $_POST['postcode'];
$result = array_diff_assoc($_SESSION['your_data'],$_POST);
print_r($result);
}
?>
Note: when I print_r either $_SESSION['your_data'] or $_POST, I can see the arrays. The goal is to send an email containing the form's updated fields using phpmail()