0
I have this chunk of code and the inputs, when I click to edit the city and click to save works normal, now if I don’t change the city, it passes as Undefined and can not save. How can I do so 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.
What is Undefined and where?
– rray
the
$city
is coming as Undefined when I do not click on the input and change the city, but when I do not change should save the same way, ie remain the one that is already there.– Ana Carolina Ribeiro
Is it a checkbox? could put the form tbm.
– rray
@rray is an input, actually when I click on the input and type for example the letter C, it lists all cities with C, then select some and click save it saves normal. Now if I for example change the street and do not change the city it will not let insert. When I give an Alert in city it passes me Undefined when I do not change.
– Ana Carolina Ribeiro
It seems to be a javascript problem, since the inputs have no name, so js should do some process before sending the information to php.
– rray
In js I take the values that are in the input and then vio ajax upload to my php file where I update. @rray
– Ana Carolina Ribeiro