Why is this parameter (variable) not working ?

I have a page with one or more images that when user clicks an image this opens another page that should have a parameter from the sending page set. The ultimate goal is to use the parameter as a variable I can use to manipulate a mysql database.
Code posted below-
[php]
// Page1

<a href="Image Test.php?image_name=VG-658" target="new"Hello Sugar

// Page2

<?php $_GET; $myvar = $_GET; echo $myvar; ?>

<!doctype html>

Image Test

This is a test

[/php]

Please wrap your code in the php tags [ php ]. There is a button for it labeled “php.”

[php]

<a href="Image Test.php?image_name=VG-658" target="new" Hello Sugar

[/php]

First, this is broken and needs to be corrected. This,
[php] $myvar = $_GET;
echo $myvar;[/php]
Probably outputs “Array”
To get the vale from the $_GET global array, you need to use the name of the element you want.
[php]echo $_GET[‘image_name’];[/php]

I apologize for not wrapping in php tags, but using your correction it is still not working. I expect the echo to return VG-658 and it returns nothing!

It is likely that this is not correct:
[php]<a href=“Image Test.php?image_name=VG-658” target=“new”[/php]

The tag doesn’t exist in this context and there is no value of new for target. If you are looking to open a new window, you would want target="_blank"

Image Test.php is also not a good file name. You could do imageTest.php however.

Try this (copy and paste it)

page1.php:

[php]My Link[/php]

On page2.php:
[php]

<?php if ( isset( $_GET['action'] ) ) { foreach ( $_GET as $key => $val ) echo "

{$key} is holding the value {$val}

"; } else { header('location: page1.php'); }[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service