URL and If


#1

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…


#2

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


#3

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>

#4

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?


#5

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


#6

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.


#7

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


#8

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";
}
?>