jug Posted December 6, 2006 Share Posted December 6, 2006 Hi.I need to click an image and it to run some php script that sets a php variable and reloads the same page.I know it sounds simple but i've tried every different way I can think of and i'm guessing it's just something basic i've missed.I've tried onclick of the image, a href and a onclick, making the image the 'submit button' of a form etc..Any response would be appreciated.Thanks in advance.Regards,Jug Link to comment https://forums.phpfreaks.com/topic/29652-click-image-to-call-php-function/ Share on other sites More sharing options...
taith Posted December 6, 2006 Share Posted December 6, 2006 heres the easiest way of setting a link to the same page, with putting any/if $_GET[] vars[code]<a href="?op=test1"><img src=""></a>[/code]that'll link you to the same page, but have the ?op active... much easier and faster then making it a form. Link to comment https://forums.phpfreaks.com/topic/29652-click-image-to-call-php-function/#findComment-136091 Share on other sites More sharing options...
jug Posted December 6, 2006 Author Share Posted December 6, 2006 I haven't really been using variables in the URL for my site, so is there any other way? Link to comment https://forums.phpfreaks.com/topic/29652-click-image-to-call-php-function/#findComment-136092 Share on other sites More sharing options...
taith Posted December 6, 2006 Share Posted December 6, 2006 no... not efficiently... and theres no time like now to start ;-) it makes page dynamics SOOO much easier and faster... Link to comment https://forums.phpfreaks.com/topic/29652-click-image-to-call-php-function/#findComment-136096 Share on other sites More sharing options...
papaface Posted December 6, 2006 Share Posted December 6, 2006 [code]<?phpif (isset($_POST["hidden"])) {$variable = "hello";echo $variable; }else echo '<form action="' .$_SERVER["PHP_SELF"]. '" method="post" enctype="multipart/form-data"><INPUT TYPE="image" SRC="imageurl" BORDER="0" ALT="Submit Form"><input name="hidden" type="hidden" value=""></form>';?>[/code]That would do what you want, i think. Link to comment https://forums.phpfreaks.com/topic/29652-click-image-to-call-php-function/#findComment-136103 Share on other sites More sharing options...
jug Posted December 7, 2006 Author Share Posted December 7, 2006 Spot on - works perfectlyThanks!Jug Link to comment https://forums.phpfreaks.com/topic/29652-click-image-to-call-php-function/#findComment-136780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.