akrytus Posted August 9, 2006 Share Posted August 9, 2006 I searched every where I cant figure this out. How can you run a php script on a user click? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 9, 2006 Share Posted August 9, 2006 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 Quote Link to comment Share on other sites More sharing options...
akrytus Posted August 9, 2006 Author Share Posted August 9, 2006 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! Quote Link to comment Share on other sites More sharing options...
akrytus Posted August 9, 2006 Author Share Posted August 9, 2006 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? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 9, 2006 Share Posted August 9, 2006 Do you mean do something likje this:[code=php:0]<?phpif(isset($_GET['test'])){ echo $_GET['test'];}?><a href="test.php?test=hello">Test</a>[/code] Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 9, 2006 Share Posted August 9, 2006 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. Quote Link to comment Share on other sites More sharing options...
akrytus Posted August 9, 2006 Author Share Posted August 9, 2006 Output: Link1 Link2 Link3User: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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 9, 2006 Share Posted August 9, 2006 Take a closer look at WildTeen88's post and explain why that isn't the solution. Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 9, 2006 Share Posted August 9, 2006 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). Quote Link to comment Share on other sites More sharing options...
akrytus Posted August 10, 2006 Author Share Posted August 10, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.