I have this code snippet and the inputs, when I click to edit the city and click to save works normal, now if I do not change the city, it passes as undefined and I can not save. How can I do it so that when I do not change the city store the same way?
if ($street === $streetOriginal && $town === $townOriginal){
$stmtSaveAddress = $conn->prepare("UPDATE address SET street = :street, number = :number, town = :town, complement =
:complement, city_id = (select city.city_id from city where city.link = :cityLink)
WHERE address_id = :address");
$stmtSaveAddress->bindValue(':street', $street);
$stmtSaveAddress->bindValue(':number', ($number <= 0 ? NULL : $number));
$stmtSaveAddress->bindValue(':town', $town);
$stmtSaveAddress->bindValue(':cityLink', $city);
$stmtSaveAddress->bindValue(':complement', $complement);
$stmtSaveAddress->bindValue(':address', $addressId);
echo 'city: '.$city;
if ($stmtSaveAddress->execute()) {
echo 'trueaddress';
}else{
echo 'falseaddress';
}
Form:
<div class="inputs-without-icon" id="box-city">
<input id="city" type="text" maxlength="100" placeholder="*Cidade" list="cities-list" value="<?php echo "{$Menu->getAddressCityName()} - {$Menu->getAddressState()}"; ?>" onkeyup="charByCharCity(this.value);">
<input id="street" type="text" placeholder="*Rua" maxlength="70" value="<?php echo $Menu->getAddressStreet(); ?>">
</div>
<datalist id="cities-list"><option data-number='0' value='Nome - Estado'>Cardápios</datalist>
This is my form.