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
Share on other sites

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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.