dan_t Posted December 8, 2008 Share Posted December 8, 2008 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 More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 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 More sharing options...
dan_t Posted December 8, 2008 Author Share Posted December 8, 2008 Darn you guys are good! OK, even though I don't quite understand it, it worked. But why didn't it work without that? Link to comment https://forums.phpfreaks.com/topic/135998-wont-work/#findComment-709072 Share on other sites More sharing options...
dan_t Posted December 8, 2008 Author Share Posted December 8, 2008 oh, and what in the world is that "zz" thing? I have never seen that before. Dan Link to comment https://forums.phpfreaks.com/topic/135998-wont-work/#findComment-709074 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.