I am trying to use a variable outside of a while loop which is in a foreach loop, but it works in the loop and displays the correct date. But when used outide the loop it displays incorrect date 01/01/1970.
I would be grateful if someone could point out my error. Many thanks.
$Destdate = $_POST['box_rtv'];
$brtvarray = array();
$brtvarray = $Destdate;
$ddate = array();
foreach ($brtvarray as $destbox) {
$sql = "SELECT destroydate FROM act WHERE item = '".$destbox."'";
$result = mysqli_query($conn, $sql) or die('Error selecting item: ' . mysqli_error($conn));
if (mysqli_num_rows($result) > 0) {
while ($row_code = mysqli_fetch_array($result)) {
$ddate[] = date('d/m/Y', strtotime($row_code['destroydate']));
}
}
}
$company = strtoupper(mysqli_real_escape_string($conn, $_POST['rtvcompany']));
$activity = "Box Retrieval";
$address = ucwords(mysqli_real_escape_string($conn, $_POST['address']));
$service = ucwords(mysqli_real_escape_string($conn, $_POST['service']));
$success = 'SUCCESS';
$authorised = ucwords(mysqli_real_escape_string($conn,$_SESSION['ls_name_usr']));
$dept = strtoupper(mysqli_real_escape_string($conn,$_POST['rtvdept']));
$boxitems = $_POST['box_rtv'];
$box = implode(",",$boxitems);
$array = array();
$array = $boxitems;
foreach ($array as $boxes) {
$outString .= "$box" . " ";
$sql = "INSERT INTO `act` (service, activity, department, company, address, `user`, `date`, destroydate, item, new) VALUES ('$service', '$activity', '$dept', '$company', '$address', '$authorised', NOW(), '".$ddate."', '$boxes', 1)";
$result = mysqli_query($conn, $sql) or die ('Error inserting box:' . mysqli_error($conn));
$sql = "UPDATE boxes SET status = 1 WHERE customer = '$company' AND custref = '$boxes'";
$result = mysqli_query($conn, $sql) or die ('Error updating box:' . mysqli_error($conn));
$sql = "UPDATE files SET boxstatus = 1 WHERE customer = '$company' AND boxref = '$boxes'";
$result = mysqli_query($conn, $sql) or die ('Error updating filebox:' . mysqli_error($conn));
}
$json = array($box);
$result = json_encode($json);
echo $result;
$row_code['destroydate']?29/05/018Thanks018and not2018or18?