-6

Possible Duplicate:
How do I run PHP code when a user clicks on a link?

I have an image .

<image name="" src="">

I have a php code that needs to be run only after the image has been clicked.

<?php

$var = somthing;
if(condition)
{
    sql stmts;
}

?>

like that.

Both are in the same php page. PLease help me to sort out this problem.

Thanks..

Community
  • 1
  • 1
Sanjeev
  • 17
  • 1
  • 6
  • 3
    Please learn at least elementary basics about technologies you are trying to use first. The keyword you missed here is "server side". – Marcin Orlowski Oct 03 '12 at 12:06
  • PHP is server side and javascript, if you want to run SQL after clicking an image you need an AJAX request – EaterOfCode Oct 03 '12 at 12:07
  • Wrap the image in a link and call the page with an additional GET parameter to decide whether or not to execute the statements. – Louis Huppenbauer Oct 03 '12 at 12:07
  • Php runs in the server, javascript runs in the browser. You sound like you have a situation than requires the use of Ajax (In which a javascript event can request data from a php page) – enhzflep Oct 03 '12 at 12:07
  • Please before you start to programme in some environment, in your case in web, learn how things work first. You'll save nights of solving some basic questions. – Zaffy Oct 03 '12 at 12:10

2 Answers2

2

You can send a request with javascript. With jQuery that would look like this:

$.get("yourfile.php?function=imageClick", function(data){});

In your php somewhere at the top add:

if($_GET['function'] == 'imageClick'){
  // do your php stuff
}
D-32
  • 3,245
  • 2
  • 22
  • 33
0

You can't run PHP code on the client side.

You can do that through an AJAX call: http://www.w3schools.com/ajax/default.asp

Chris Forrence
  • 10,042
  • 11
  • 48
  • 64