I'm trying to pull all the "totalsDate" values from a table "totals" and then either INSERT a new record or UPDATE an existing one based on a variable $date.
//getting all the dates from the totals table and assigning to row
$sqlDate = "SELECT totalsDate FROM totals";
$query = mysqli_query($dbCon, $sqlDate);
//$row = mysqli_fetch_array($query);
while($row = mysqli_fetch_array($query)){
$rowDate = $row['totalsDate'];
//if statement to either update the totals table or create a new record
if($rowDate = $date){
$sqlThree = "UPDATE totals SET lodgements = '$lodgementsAfter' WHERE branch_name = '$branchTest' AND totalsDate = '$date'";
$query = mysqli_query($dbCon, $sqlThree);
}
else {
$sqlFour = "INSERT INTO totals VALUES(NULL, '$branchTest', 0, '$amount', 0, '$date')";
$query = mysqli_query($dbCon, $sqlFour);
}
}
The update part works, however my else statement will never be executed and a new record cannot be entered. I also get this error:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in
I'm a bit confused on using the mysqli_fetch_array and how to actually use the data?
Thanks for any help.