catflea Posted January 27, 2009 Share Posted January 27, 2009 I'm currently sat in class and the lecturer is being no help whatsover, and I've tried everything I can think of to get this working. I need to use $ request in a while loop to create an output of something along the lines of "you like tea, you like coffee" in PHP from a set of checkboxes. The code I have been given for the checkboxes (which is in a different file to the PHP) is <p>Hot drinks I like (checkboxes)</p> <label>Tea<input type="checkbox" name="drink[]" value="tea" checked="checked" /></label> <label>Coffee<input type="checkbox" name="drink[]" value="coffee" /></label> <label>Malted milk<input type="checkbox" name="drink[]" value="milk" /></label> and the code I have done so far is <?php $i = 0; while ($i <= 3) { echo $i, $REQUEST['drink[$i]']; if ($REQUEST['drink[$i]'] <> null) { echo "you like to drink", $_REQUEST['drink[$i]'], "."; } $i++; } ?> but I am really really stuck with this one - spent over an hour staring at it and trying the PHP manual and google and I'm getting no joy. Any help at all would be appreciated! Not nessecarily looking for the answer (although that would be nice!) pointers as to what I am doing wrong would be good. (this btw, is only my second class on this unit and I've not done PHP before, so please be nice ) Quote Link to comment Share on other sites More sharing options...
haku Posted January 27, 2009 Share Posted January 27, 2009 Not nessecarily looking for the answer That's good, because you didn't actually ask a question. But, your problem probably lies in the fact that you are using $REQUEST, when you should be using $_REQUEST. That being said, you shouldn't really use either of them, and should use $_POST, $_GET and/or $_COOKIE. It's better to be more specific. But honestly, your professor probably doesn't know that - professors are usually not up to date with current standards. Quote Link to comment Share on other sites More sharing options...
catflea Posted January 27, 2009 Author Share Posted January 27, 2009 Hi Haku, that was a bit of a noob error. I finally came on the actual solution <?php $i = 0; while ($i <= 3) { if ($_REQUEST['drink'][$i]) { echo "You like to drink ", $_REQUEST['drink'][$i], ". "; } $i++; } ?> 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.