Jump to content

Recommended Posts

Hi, thanks for reading. I have a scenario...

 

I have a page called page.php.

 

On that page holds the sentence "This is some text."

 

When I click a link from that page that links to page.php?task=hello, the text displays "Hi. Thanks for clicking me." but it also displays "This is some text."

 

Is there anyway to configure and/or prevent "This is some text." from displaying?

Link to comment
https://forums.phpfreaks.com/topic/154242-solved-stop-page-from-displaying/
Share on other sites

The following is the code:

 

<?php

include('config.php');

if (isset($_GET['task']))
{
  $task = ($_GET['task']);

if ($task == "hello")
{
  $task = hello();
} else {
  echo "";
}

function hello()
{

return "
Hi. Thanks for clicking me.";

}

?>
<html>

<head>

<title>Test</title>

<link rel=stylesheet type=text/css href=layout.css>

</head>

<body>

<div id=container>

<a href="page.php?task=hello">Hello</a>

<br><br>
This is some text.

</div>

</body>

</html>

Get rid of the, "This is some text", and replace it with $body.  There's no need for a function here, but I assume you're going to use this for a bigger script so I'll leave it.

 

if ($_GET['task'] == "hello") {
   $body = hello();   
} else {
   $body = "This is some text";
}

function hello()
{
   return " Hi. Thanks for clicking me.";
}

 

Yeah, just planning ahead, and learning.

 

Thanks Maq for this - I greatly appreciate it.

 

Sure. 

 

This will work well for your small example, but if you were to write a bigger script or application there could be a better solution depending on certain factors.  You should always think ahead and create a good model and design for your application.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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