MrCreeky Posted July 2, 2009 Share Posted July 2, 2009 I just want to show an area on a page if the GET string is set to true i.e. .php?string=true <?php $string == $_GET if ($string === "true") { } else { } ?> That's what I came up with after quickly looking at my book but it errors. Could someone show where where I'm going wrong. This is very simple I'm sure but I don't do much php coding. Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/ Share on other sites More sharing options...
johnathanhebert Posted July 2, 2009 Share Posted July 2, 2009 $_GET is an array, with the keys set to the parameter names on the query string, and the values set to the values on the query string... you are also missing the semicolon after your first statement -- so try: $string = $_GET["string"]; or just: if ($_GET["string"]==="true") Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-867794 Share on other sites More sharing options...
MrCreeky Posted July 2, 2009 Author Share Posted July 2, 2009 Using this: <?php $string = $_GET["string"]; if ($string === "true") { } else { } ?> I get an error of: Undefined index: string on line 2 Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-867869 Share on other sites More sharing options...
iPixel Posted July 2, 2009 Share Posted July 2, 2009 try this.... $string= isset($_GET[string]) ? $_GET[string] : null; if (!is_null($string)) { $string= $_GET[string]; } This should avoid that error . Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-867877 Share on other sites More sharing options...
MrCreeky Posted July 2, 2009 Author Share Posted July 2, 2009 Hi, that give this error: Notice: Use of undefined constant string - assumed 'string' Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-867885 Share on other sites More sharing options...
gevans Posted July 2, 2009 Share Posted July 2, 2009 <?php $foo = isset($_GET['string']) ? $_GET['string'] : null; if(!is_null($foo)) { echo 'true'; } else { echo 'false'; } Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-867887 Share on other sites More sharing options...
iPixel Posted July 2, 2009 Share Posted July 2, 2009 MrCreeky... is $string predefined as anything anywhere else above this code? then again maybe $gevans was onto something... dont call the variable "$string" use something else. Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-867894 Share on other sites More sharing options...
MrCreeky Posted July 3, 2009 Author Share Posted July 3, 2009 <?php $foo = isset($_GET['string']) ? $_GET['string'] : null; if(!is_null($foo)) { echo 'true'; } else { echo 'false'; } Using this works just fine for my page but how would I be able to use html with the echo output without having to comment out parts like this: class=/"none/" ? Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-868289 Share on other sites More sharing options...
gevans Posted July 3, 2009 Share Posted July 3, 2009 You can tkae alook at the heredoc syntax; http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc This will allow you to do the following... <?php $foo = isset($_GET['string']) ? $_GET['string'] : null; if(!is_null($foo)) { echo <<<EOD <span class="whatever">'single quotes as well'</span> EOD; } else { echo <<<EOD <span class="whenever">'single quotes as well'</span> EOD; } Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-868291 Share on other sites More sharing options...
MrCreeky Posted July 3, 2009 Author Share Posted July 3, 2009 That would work well for a simple html statement but I have a large form. Is there a different way to do that? Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-868321 Share on other sites More sharing options...
gevans Posted July 3, 2009 Share Posted July 3, 2009 What else do you want? Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-868374 Share on other sites More sharing options...
Adam Posted July 3, 2009 Share Posted July 3, 2009 <?php $foo = isset($_GET['string']) ? $_GET['string'] : null; if(!is_null($foo)) { echo <<<EOD <table width="1000000"> <tr> <td>You could fit a big table in here!</td> </tr> </table> EOD; } else { echo <<<EOD <span class="whenever">'single quotes as well'</span> EOD; } Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-868375 Share on other sites More sharing options...
gevans Posted July 3, 2009 Share Posted July 3, 2009 @MrAdam That first EOD; needs the space before it removed. Link to comment https://forums.phpfreaks.com/topic/164525-very-simple-get-help/#findComment-868379 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.