I have two javascript variables var 1 and var 2 which I need to pass to PHP through GET method.
$('#output_images').html('<img src="MergeIcons.php?icon1=var1&econdIcon=var2 />');
In my .php file, I merge two icons using GD PHP and send the image back using imagepng.
$firstIcon = $_GET['icon1'];
$secondIcon = $_GET['icon2'];
// Process images
header('Content-Type: image/png');
imagepng($dest);
When I pass the direct image path and dont use the var1 and var 2 it works fine, but with var1 and var 2 it doesnt work. What could be the problem?
Currently you are sending var1 and var2 to PHP as strings. They need to be sent as variables...
$('#output_images').html('<img src="MergeIcons.php?icon1='+var1+'&econdIcon='+var2+'" />');
Are you simply not concatentating the values correctly. If you don;t want literal var1
and var2
perhaps try this:
$('#output_images').html('<img src="MergeIcons.php?icon1='+var1+'&econdIcon='+var2+'" />');
You also need to make sure your parameter names match in javascript and PHP (they don't for icon2
right now)
Assuming you copy and pasted it, I do see a typo in the url, &econdIcon=var2, might need to be &icon2=var2
Also Mike Brant is right they need to be concatenated.