Jump to content

Archived

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

akrytus

Onclick PHP script

Recommended Posts

I searched every where I cant figure this out.  How can you run a php script on a user click?

Share this post


Link to post
Share on other sites
If you want to run a PHP scriupt when you click a link/button/image without the user being sent to the PHP script itseft you'll want to use AJAX. AJAX is javascript, but it allows you to called server side scripts in the background without having to reload the page. Check out [url=http://www.ajaxfreaks.com/tutorials/1/0.php]this introduction[/url] tutorial over at ajaxfreaks.com

Share this post


Link to post
Share on other sites
I appreciate the link and help.  I submitted help into the forums, and no one seems to respond.  Not nearly as many user as this forum.  I looked at many examples and tutorials and cant seem to find what I need.  Perhpas you could give me some pointers  if you do not mind.  Thankyou much!

Share this post


Link to post
Share on other sites
Alright check this out, I am racking my brain here and this is a very difficult concept to understand and accomplish in my opinion.  Let me re-explain.

The only way I know how to send client side information to a server is through a form.  This is slow and clumsy to me, I want to use links that are created when a page loads through a php script.  These links are dynamic so I cant just create these myself, they must be created through a script.
  When you click a link, I need to know which link was clicked so I can send that data to a php script.  Using Ajax, only allows you to run php script to send Ajax data without a refresh, not the other way around.  You cannot send a php script data from Ajax, or any javascript that I am aware of.

Am I truely limited to using a form or is there a way that I am not aware of using either Ajax or any other method? 

Share this post


Link to post
Share on other sites
Do you mean do something likje this:
[code=php:0]<?php

if(isset($_GET['test']))
{
    echo $_GET['test'];
}

?>
<a href="test.php?test=hello">Test</a>[/code]

Share this post


Link to post
Share on other sites
What do you want the PHP script to actually do? Is it going to be echoing anything to the browser, or is it just updating a database? As, depending on what you want to do there is another solution, a little like Ajax but easier to do.

Share this post


Link to post
Share on other sites
Output:

  Link1
  Link2
  Link3


User:

Click Link1 -> Send the data that tells the php script that link1 was clicked.


PHP:

Sees link1 was clicked therefore do this;


Its like choosing from a dynamic drop down menu in a form.  But instead I want to use links.  Without using a form, I dont know how to send what was chosen by the user to the php script.  What it does is irrelevant, what it does depends on what link was chosen.  Again the links are dynamic so I cant predefine what it does, it must create it all on its own.


Share this post


Link to post
Share on other sites
Take a closer look at WildTeen88's post and explain why that isn't the solution.

Share this post


Link to post
Share on other sites
What I'm trying to establish is whether you want the browser to relocate to the script being clicked on. If so, that's easy: just add a query string on the end of the URL, e.g.
[code]
<a href="myscript.php?var1=1&var2=10&var3=20">My link</a>
[/code]

and you then get the values in the PHP script in the $_GET array, just like you get them from a form using the $_POST array.

If you don't want to relocate the browser to the script, but just want to call it, there is a way to do it with Javascript (or even without the javascript but in a less useful way).

Share this post


Link to post
Share on other sites
You guys are brilliant, I appologize to Wildteen88, I just didnt understand it in your example, but you were right.  I never thought about sending it through the URL like that, I am so stupid.  Still learning.  Thankyou for your help everyone. 

Share this post


Link to post
Share on other sites

×

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.