0
if ($stmtMoreInformations->execute()) {
$stmtUpdateMoreInformations = $conn->prepare("UPDATE menu SET only_delivery = :delivery, card_on_delivery = :delivery,
wifi = :wifi, live_music = :music, open_holiday = :holiday,
acessible = :acessible
WHERE menu_id = :menu");
$stmtUpdateMoreInformations->bindValue(":menu", $menu);
}
I have this update and my variables are returning 1 or 2, I want to force them to return true or false, can I use the cast? How could I use it?
$menu = $_POST['menu'];
$delivery = null;
if (isset($_POST['delivery'])) {
$delivery = $_POST['delivery'];
}
$cards = null;
if (isset($_POST['cards'])) {
$cards = $_POST['cards'];
}
$wifi = null;
if (isset($_POST['wifi'])) {
$wifi = $_POST['wifi'];
}
$music = null;
if (isset($_POST['music'])) {
$music = $_POST['music'];
}
$holiday = null;
if (isset($_POST['holiday'])) {
$holiday = $_POST['holiday'];
}
$acessible = null;
if (isset($_POST['acessible'])) {
$acessible = $_POST['acessible'];
}
$stmtMoreInformations = $conn->prepare("SELECT only_delivery, card_on_delivery, wifi, live_music,
open_holiday, acessible FROM public.menu
WHERE menu_id = :menu");
$stmtMoreInformations->bindValue(":menu", $menu);
if ($stmtMoreInformations->execute()) {
$stmtUpdateMoreInformations = $conn->prepare("UPDATE menu SET only_delivery = :delivery, card_on_delivery = :card,
wifi = :wifi, live_music = :music, open_holiday = :holiday,
acessible = :acessible
WHERE menu_id = :menu");
$stmtUpdateMoreInformations->bindValue(':menu', $menu);
$stmtUpdateMoreInformations->bindValue(':delivery', $delivery);
$stmtUpdateMoreInformations->bindValue(':card', $cards);
$stmtUpdateMoreInformations->bindValue(':wifi', $wifi);
$stmtUpdateMoreInformations->bindValue(':music', $music);
$stmtUpdateMoreInformations->bindValue(':holiday', $holiday);
$stmtUpdateMoreInformations->bindValue(':acessible', $acessible);
$stmtUpdateMoreInformations->execute();
echo'delivery: '.$delivery;
echo'card: '.$cards;
echo'wifi: '.$wifi;
echo'music: '.$music;
echo'd: '.$holiday;
}
If you put a snippet of html with radio, it can be easier to adjust the answer to the specific case (and help people who can post new answers or alternatives).
– Bacco
If you want to adapt to your question on the same subject (which you deleted a little), just use
if( isset($_POST['cards'] ) && ($_POST['cards'] =='1') ) {
etc to use white or empty for false, 1 and for true.– Bacco
Thanks @Bacco but I haven’t solved my real problem yet.
– Ana Carolina Ribeiro
If you post a question with HTML code and more PHP we can try to help. I would suggest you stop insisting on the cast/bool because this is definitely not the problem. PHP doesn’t have this type of typing problem. When asking new question, put the two parts, explain what is happening that we try to help.
– Bacco
This problem in question I’ve already solved, I’m making another comparison now. Between what’s coming from the bank and what’s coming from my radio input. But thank you.
– Ana Carolina Ribeiro
Okay, but the tip is for any post you post. Always put the snippet of updated code, SQL in the database part, etc. - And on recovering radios from DB, if you want to use the same option.
if( $valordodb = 'seu_verdadeiro') $s1=' selected' else $s2=' selected'
, then you put in html<option value ..... <?=$s1?>>
at the end of the true and $s2 at the false (Selected is for option, checked for checkbox) but the logic is the same.– Bacco
Okay, thank you so much for the tip!
– Ana Carolina Ribeiro