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. Quote Link to comment 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") Quote Link to comment 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 Quote Link to comment 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 . Quote Link to comment 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' Quote Link to comment 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'; } Quote Link to comment 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. Quote Link to comment 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/" ? Quote Link to comment 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; } Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
gevans Posted July 3, 2009 Share Posted July 3, 2009 What else do you want? Quote Link to comment 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; } Quote Link to comment 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. 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.