Jump to content

[SOLVED] Check boxes & PHP


catflea

Recommended Posts

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  ;D )

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.