Jump to content

Click image to call php function


jug

Recommended Posts

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

[code]<?php

if (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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.