Pass Get Variable (noob)
Moderator: General Moderators
Pass Get Variable (noob)
How can I pass the variable $_GET[x] when it equals xx ($_GET[sc] = xx) when I click on an image? I cannot just echo the html code I need because I am doing a rollover image in dreamweaver, and for some reason it won't work.
Foxy
Foxy
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Pass Get Variable (noob)
I'm not exactly sure the issue you are having because of rollover images. All you simply need to do is check $_GET['sc'] == xx and append it to the url.
I.e.,
or
I.e.,
Code: Select all
$imagepath = "yourscript.php";
if (!empty($_GET['sc']) && $_GET['sc'] == 'xx') {
$imagepath .= '?sc=xx';
}
echo $imagepath;Code: Select all
yourscript.php<?php echo !empty($_GET['sc']) && $_GET['sc'] == 'xx' ? '?sc=xx' : ''; ?>Re: Pass Get Variable (noob)
I am not sure if I understand this, but I don't think it is the correct solution, I will try to explain better.
This is my image link:
But I need to add $_GET[sc] to the url, so I try this:
But my rollover image doesn't work (rolling over doesn't change image) but the link works correctly, it seems that dreamweaver does it in javascript.
Foxy
This is my image link:
Code: Select all
<a href="buy.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('x','','images/menubar/buy2.gif',1)"><img src="images/menubar/buy.gif" alt="" name="x" width="150" height="100" border="0" id="x"/>Code: Select all
<?php
echo "<a href='buy.php?sc=".$_GET[sc]."' onmouseout='MM_swapImgRestore()' onmouseover='MM_swapImage('buyRoll','','images/menubar/buy2.gif',1)'>";
echo "<img src='images/menubar/buy.gif' name='buyRoll' width='150' height='100' border='0' id='buyRoll'/></a>";
?>Foxy
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Pass Get Variable (noob)
The example I've shown is in fact what you are after.
Can you post the generated HTML with the SC parameter present? Everything looks ok in the code you posted, however, I suspect you are getting notices within your script because you are perhaps using an initialized variable (which is why I add the empty() checks in my example).
Can you post the generated HTML with the SC parameter present? Everything looks ok in the code you posted, however, I suspect you are getting notices within your script because you are perhaps using an initialized variable (which is why I add the empty() checks in my example).
Re: Pass Get Variable (noob)
Sorry I am still quite confused, are you saying I might be running into problems because of an initialized variable (or function?) that isn't in the scope? And I don't think I understand your first script, I don't know too much about PHP. Actually what I am confused about is this part of the code:
Code: Select all
$imagepath = "yourscript.php";Re: Pass Get Variable (noob)
I think John Cartwright means that you should check that $_GET['whatever'] exists before using it...which is indeed true 
And his code is a demonstration of how you can append the value of $_GET['sc'] to the query string of the script you're trying to run.
And his code is a demonstration of how you can append the value of $_GET['sc'] to the query string of the script you're trying to run.
Re: Pass Get Variable (noob)
Well it is not a problem appending $_GET[sc] to the url, because it works fine with the code I have. My problem is that my pop-up image is not working correctly when echo it with php (so I can append $_GET[sc] to the url.)
The pop-up image is done with dreamweaver, I don't know if there would be a problem with the scope, but the thescript functions are declared outside of my php code, and this is declared outside of the php code, it is the image that should pop-up:
If this is the problem can I initialize onload in the php, and still have the <body> tag where it is originally?
Foxy
The pop-up image is done with dreamweaver, I don't know if there would be a problem with the scope, but the thescript functions are declared outside of my php code, and this is declared outside of the php code, it is the image that should pop-up:
Code: Select all
<body onload="MM_preloadImages('images/menubar/buy2.gif')">Foxy
Re: Pass Get Variable (noob)
What do you mean by not working correctly?
This seems like a javascript problem, not php.
In which case I suggest you make use of the firefox error console (I find firefox's particularly good, but most browsers have one).
This seems like a javascript problem, not php.
In which case I suggest you make use of the firefox error console (I find firefox's particularly good, but most browsers have one).
I'm not really sure what you mean by that.If this is the problem can I initialize onload in the php, and still have the <body> tag where it is originally?
Re: Pass Get Variable (noob)
I ran the error console in firefox and I got this:
Error: syntax error
Source File: http://.../index_beta.php
Line: 1, Column: 12
Source Code:
MM_swapImage(
It happens every time I go to roll over the image, so I guess it is a javascript problem. But the problem goes away when I don't put my html code in php (echo the link like before.)
Foxy
Error: syntax error
Source File: http://.../index_beta.php
Line: 1, Column: 12
Source Code:
MM_swapImage(
It happens every time I go to roll over the image, so I guess it is a javascript problem. But the problem goes away when I don't put my html code in php (echo the link like before.)
Foxy
Re: Pass Get Variable (noob)
Ooooooh I see - you've got nested quotes. You need to use either double quotes in your html, or javascript.
Here:
Here:
Code: Select all
onmouseover='MM_swapImage('buyRoll','','images/menubar/buy2.gif',1)'Re: Pass Get Variable (noob)
Where would I add the double quotes? Wouldn't it make my php not work?
Re: Pass Get Variable (noob)
Yes, so you need to escape them with a backslash. You need to replace one set of quotes with double quotes.
Re: Pass Get Variable (noob)
Thanks that worked great!
Foxy
Foxy
Re: Pass Get Variable (noob)
Phew 
Cool, no problem.
Cool, no problem.