Jump to content

Won't work.


dan_t

Recommended Posts

Hello everyone,

I was fiddling with what I thought would be simple, but I can't get it to work. I would like some one to check it out andtell me why.

Thanks


<select name="find">
<option value="a">I'm a regular customer</option>
<option value="b">TV Advertising</option>
<option value="c">Phone directory</option>
<option value="d">Word of mouth</option>
   </select>

 

<?php
if ($find == "a") {
    echo "<p>Regular customer.</p>";
} elseif ($find == "b") {
    echo "<p>Customer referred by TV advert.</p>";
} elseif ($find == "c") {
    echo "<p>Customer referred by phone directory.</p>";
} elseif ($find == "d") {
    echo "<p>Customer referred by word of mouth.</p>";
}   else {
    echo "We do not know how this customer found us.</p>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/135998-wont-work/
Share on other sites

That is assuming register_globals is on...try this:

 

<?php
$find = isset($_REQUEST['find'])?trim($_REQUEST['find']):"zz";
if ($find == "a") {
    echo "<p>Regular customer.</p>";
} elseif ($find == "b") {
    echo "<p>Customer referred by TV advert.</p>";
} elseif ($find == "c") {
    echo "<p>Customer referred by phone directory.</p>";
} elseif ($find == "d") {
    echo "<p>Customer referred by word of mouth.</p>";
}   else {
    echo "We do not know how this customer found us.</p>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/135998-wont-work/#findComment-709021
Share on other sites

register_globals would set any type of request from a form (when you submit a form it sends data via POST or GET, get by default).

 

What the globals would do is take a form item, such as your text field find, and use that name for the variable name. But that turned how to be a huge security flaw so it is now disabled. Now to access the methods sent from a form, it can be accessed by $_REQUEST ($_GET and $_POST combined) or $_GET, if the form was submitted using get, or $_POST if the form was submitted using POST.

 

Hope that helps.

 

EDIT:

The zz is just not in the if statement, so we know that will not be executed.  The statement goes as folllows

 

$find = isset($_REQUEST['find'])?trim($_REQUEST['find']):"zz";

 

If find in request has been set, then set $find equal to that variable trimmed, else set it to zz since that will not be executed in the if statement.

 

Basically that is just a shortened if statement. To the left of the colon (:) it means the if was true to the right it is like an "else" statement.

Link to comment
https://forums.phpfreaks.com/topic/135998-wont-work/#findComment-709079
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.