Miko Posted April 20, 2009 Share Posted April 20, 2009 Hello, I'm making a form with a search input + 3 different checkboxes. So making the form is absolutely no problem, the search input either. The thing that I want is that a user can select one of the 3 checkboxes and in function of that (+ search input) they will search in the database. Anyone an idea how to pull this together? Thanks,! Link to comment https://forums.phpfreaks.com/topic/154837-solved-php-checkboxes/ Share on other sites More sharing options...
Yesideez Posted April 20, 2009 Share Posted April 20, 2009 If you want the user to be allowed to only select one item out of a possible three your best bet would be to use radio buttons instead. Link to comment https://forums.phpfreaks.com/topic/154837-solved-php-checkboxes/#findComment-814327 Share on other sites More sharing options...
Miko Posted April 20, 2009 Author Share Posted April 20, 2009 Thought allso that would work but it strangely enough, it doesn't. I can still click all three at the same time ??? Link to comment https://forums.phpfreaks.com/topic/154837-solved-php-checkboxes/#findComment-814337 Share on other sites More sharing options...
Yesideez Posted April 20, 2009 Share Posted April 20, 2009 You're probably giving them all different names then - very common mistake and easy to make. <input type="radio" name="myradio" value="1"> Cheese <input type="radio" name="myradio" value="2"> Onion <input type="radio" name="myradio" value="3"> Cheese & Onion When you get the value of the radio button depending on which one is selected will return the correct value. Grouped radio buttons must all be named the same. Link to comment https://forums.phpfreaks.com/topic/154837-solved-php-checkboxes/#findComment-814346 Share on other sites More sharing options...
Miko Posted April 20, 2009 Author Share Posted April 20, 2009 Hi, Your right, now it works But will this work for my php script? I use $_POST and variables to define it. Link to comment https://forums.phpfreaks.com/topic/154837-solved-php-checkboxes/#findComment-814350 Share on other sites More sharing options...
Yesideez Posted April 20, 2009 Share Posted April 20, 2009 Let's make a form: <form action="<?php echo $_SERVER['PHP_SELF']; method="post"> Name: <input type="text" name="username"><br> Favourite Food: <input type="radio" name="myradio" value="1"> Cheese<br> <input type="radio" name="myradio" value="2"> Onion<br> <input type="radio" name="myradio" value="3"> Cheese & Onion<br><br> <input type="submit" name="subsend" value="Answer Questions"> Depending on the ACTION part of the FORM declaration (POST or GET) depends on how you pick up the data. POST sends data in packets where as GET appends the data onto the URL. We've used POST so we'll read it using this: $uname=$_POST['username']; $food=$_POST['myradio']; if (isset($_POST['subsend'])) { echo 'User '.$uname.' selected option '.$food; } Link to comment https://forums.phpfreaks.com/topic/154837-solved-php-checkboxes/#findComment-814354 Share on other sites More sharing options...
Miko Posted April 22, 2009 Author Share Posted April 22, 2009 Owkay, thanks! it works Link to comment https://forums.phpfreaks.com/topic/154837-solved-php-checkboxes/#findComment-816341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.