Call php inside same page

Posted on 2009-02-16
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.
Question by:tuckeroil
    LVL 28

    Accepted Solution

    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="">Go to m55</a>

                                             show the m5
                                                       show the link

    Author Comment

    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?

    LVL 28

    Assisted Solution

    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 Closing Comment

    Thanks for the help

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now