Please forgive my code as I am still learning PHP.
I am attempting to save data to the database, I was successfully able to save the variables $dobday $dobmonth $dobyear to the database. I have since added new variables - $adderssLine $townCity $postcode $country. When I enter in the details (both birthday and address) and update the database, nothing is saved. When I enter only the address variables, nothing is saved to the database. However, when I enter in only the birthday variables it is saved to the database. The table has the correct column names.
Thank you for any help and your time.
<?php
session_start();
$user=$_SESSION['firstName'];
if (isset($_POST['submit'])){
$connectDB = mysqli_connect("localhost","root","")
or die("cant connect");
//proving the database connection details and saving it as a variable
mysqli_select_db($connectDB, "registration"); //table name
// BIRTHDAY
$updateDBvalues=array();
$updateArray=array();
$dobday=$_POST['dobday'];
$dobmonth=$_POST['dobmonth'];
$dobyear=$_POST['dobyear'];
//ADDRESS
$addressLine=$_POST['addressLine'];
$townCity=$_POST['townCity'];
$postcode=$_POST['postcode'];
$country=$_POST['country'];
//ADDRESS BELOW
if(!empty($addressLine))
$updateArray[]="addressLine='".$addressLine."'";
if(!empty($townCity))
$updateArray[]="townCity='".$townCity."'";
if(!empty($postcode))
$updateArray[]="postcode='".$postcode."'";
if(!empty($country))
$updateArray[]="country='".$country."'";
//BIRTHDAY BELOW
if(!empty($dobday))
$updateArray[]="dobday='".$dobday."'";
if(!empty($dobmonth))
$updateArray[]="dobmonth='".$dobmonth."'";
if(!empty($dobyear))
$updateArray[]="dobyear='".$dobyear."'";
$updateDBvalues=$updateArray;
$updateDBvalues_imploded=implode(',',$updateDBvalues);
if(!empty($updateDBvalues)){
$query="UPDATE users SET $updateDBvalues_imploded WHERE firstName='$user'";
$connQuery=mysqli_query($connectDB,$query);
die("Succesfully updated, return to <a href='accountPage.php'>Accounts page</a>");
}else{
die ("query did not work");
}
}
?>