Puika1 Posted January 23, 2012 Report Share Posted January 23, 2012 (edited) es uztaisiju input ar checkbox kas pievieno atzimetos datus datubāzē,bet problēma radās ar to,ja ir divi checkbox logi,ja atzīmē abus,tad pievienojas datubāzē,bet ja tikai vienu nekā ;( kā var,lai pēc izvēles atzīmētu un pievienotu datubāzē? KODS if($_POST['add']){ if($_POST['twitter'] && $_POST['kontakti']){ $twitter = mysql_real_escape_string($_POST['twitter']); $kontakti = mysql_real_escape_string($_POST['kontakti']); mysql_query("INSERT INTO `pasutit`(`twitter`,`kontakti`) VALUES('$twitter','$kontakti')"); Edited January 23, 2012 by Puika1 Quote Link to comment Share on other sites More sharing options...
Kavacky Posted January 23, 2012 Report Share Posted January 23, 2012 Ja nav ieķeksēts checkbox, tad tas vispār netiek padots serverim, tāpēc POST vai GET masīvā ir tukšums. Vai nu pārbaudi, vai pirms checkbox'a ieliec hidden lauku ar defaulto neieslēgto vērtību, ķipa 0. Quote Link to comment Share on other sites More sharing options...
Puika1 Posted January 23, 2012 Author Report Share Posted January 23, 2012 (edited) Ja tu domāji "Noklusēts" tad man jau ir. `twitter` varchar(225) collate utf8_latvian_ci NOT NULL default 'Nē', `kontakti` varchar(225) collate utf8_latvian_ci NOT NULL default 'Nē', Vaj arī tu domāji kautko saistītu ar input formu <input type="checkbox" name="twitter" value="Jā" /> Šitā ar mēģināju,nekā! <input type="hidden" name="twitter" value="0" /> <input type="checkbox" name="twitter" value="Jā" /> Edited January 23, 2012 by Puika1 Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted January 23, 2012 Report Share Posted January 23, 2012 (edited) Kā tev liekas, vai zemāk esošais kods izpildīsies, ja viena no post vērtībām būs 0? if($_POST['twitter'] && $_POST['kontakti']){ Edited January 23, 2012 by xPtv45z Quote Link to comment Share on other sites More sharing options...
Puika1 Posted January 23, 2012 Author Report Share Posted January 23, 2012 (edited) xPtv45z es pēc Kavacky ieteikuma,bet kāds sakars ar POST un value? Edited January 23, 2012 by Puika1 Quote Link to comment Share on other sites More sharing options...
daGrevis Posted January 23, 2012 Report Share Posted January 23, 2012 $x = 0; if ($x) { // This will never happen! } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.