Jump to content

Very simple GET help


MrCreeky

Recommended Posts

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

$_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

<?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

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

<?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

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.