We help IT Professionals succeed at work.

Call php inside same page

tuckeroil
tuckeroil asked
on
Medium Priority
1,153 Views
Last Modified: 2012-05-06
When  a user clicks on  a <a></a> link, I want to call some PHP code.  The best way I know now to do that is create another php page and run the code that way.  Is there a way to run the script inside the page so that I do not have to create another php file?  Having a bunch of files can cause clutter and all and I hate that haha.

Thanks guys.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
You can, your link will have to point to the same page where thay are and you append a variable to the link, on the page you check if the variable has been set or net.

<a href="mydomain.com/index.php?m=55">Go to m55</a>

<?php
if(isset($_REQUEST['m'])){
                                         show the m5
                                        }else{
                                                   show the link
                                                 }

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks that worked for what I was doing, but I have a follow up question.

What if you want to submit information from a form, such as a file or a text field, how would you accomplish using the same php file?  Use the $_POST variable?

Thanks  
CERTIFIED EXPERT
Commented:
That's why I used $_REQUEST it will work with both a link or a form's post

link -> $_GET
form -> $_POST or $_GET depending of the method used in the form tag

$_REQUEST work with both $_GET or $_POST

Author

Commented:
Thanks for the help
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.