URL and If

Similar to a form submit, but how do I pass a URL and have an if statement work for me.

Example: I’ll have a http://www.url.com/index.php?info=object1 and when click it reloads the same page, in this case the index.php and then display something, text like for object1 and so on with elseif.

I hope I explained that right…

What exactly is your problem? What does your script (not) do?
Could you post the part of the script that malfunctions?

Here is what I have so far on a page called index.php

<?php
if (isset($_GET['info']))
	{
if (empty($1))
{
$ermessage = "Error:";
echo "Object One"; exit();
}
}
?>

<a href="index.php?object=1">Object One</a>

That all?

Question: What does the variable $1 do? Where does it come from?

What’s the output of this script? And what would you like it to do instead?

That’s it. I want it to display the Words Object One when the url is clicked on…

Ok, If I am understaning this correctly you are trying to get a variable into the URL and then back out again and display the variables value.

Here is a sample script, should work or at least give you a good understanding of what you can do with $_GET[’’]

[php]

<? $object = $_GET['variable']; if(isset($object)) { if(empty($object)) { echo "Empty Variable!"; //should output - value } else { echo $object; //Outputs: 1 } } else { ?>

Object One

<? } ?>

[/php]

Note: Remember… Numbers cannot be used as variables - $1 is invalid.
I know Apache and PHP can create variables using them, but we can not.

Your on the right track for what I want, but it does not work. Nothing is displayed (echoed)…

I found what I wanted YEA! :P

<a href="url.php?object=1">Object One</a><br>
<a href="url.php?object=2">Object One</a><br>
<a href="url.php?object=3">Object One</a><br>
<br><br><br><br>
<?
$object = $_GET['object'];
if(isset($object))
{
   	if ($object=="1")
   		echo "One";
	elseif ($object=="2")
		echo "Two";
	else
		echo "Huh";
}
?>
Sponsor our Newsletter | Privacy Policy | Terms of Service