Jump to content

Calling PHP Funcitons using Buttons


tom.park89

Recommended Posts

Hi Guys,

 

I am writing a web site for a Company. I have two issues the First one is how can or is it possable to check weather a user is logged in and then call on of two functions depending on the outcome.

 

The second one and the more important ones is it possable to call a PHP Function by a user Clicking a Link or a button? If it is possable how would I go about doing this.

 

Each functions build a different section of the site so for Example;

 

The Function 'Data' will bring back a table displaying the Data from a set table, and then the Function 'Data_Input' would display a different page that allows the users to input data to the tables. I don't want these two functions to be dispalying at the sametime but to one Display and then the other and so on for other functions.

Link to comment
Share on other sites

I have answered my first Question, the answer to that one was right in front of me. As for the Second question (Call PHP Functions from Button Click) I'm not sure how to even start going about doing this. I was thinking may I would have to use Java Script to do this or could it be done just using HTML and PHP.

 

I was thinking something like <input type='button' name='home' onclick='functionanem' >

 

Or something similar, I having a mental block on php as I haven't used it in about 6 months as I have been working on a .NET project.

 

Any pointers or sujestion as to how I could go about doing this would help me alot.

 

Thanks for any posts or tips.

 

Regards

Thomas

Link to comment
Share on other sites

Ajax isn't necessary unless you don't want the page to refresh.  The bare-bones basic version would be to simply make the buttons form submit buttons, and have your page post to itself.  Based on what button was pressed, different info would be shown.

 

That's how ASP.NET webforms tend to work (have you ever noticed how everything is actually taking place in a form, hense the term 'webforms'?).

 

This is a common pattern on the web.  For more info google 'page controller'.

Link to comment
Share on other sites

Not to be rude, at all, but if you don't know PHP too extremely well, I doubt you'll want to venture down the road of AJAX as you'll need to know PHP, and JavaScript (fairly well).

 

Might I suggest looking into the possibility of just using jQuery? If you don't need to fetch anything dynamic, jQuery should work just fine.

Link to comment
Share on other sites

It's not I don't know PHP that well, I have used it on projects before. I just I haven't used in over a year and I'm just trying to refresh my memory on what I can and carn't do with it. I have spent the last year teaching myself C# and .NET Programming as my employer wanted us all to work on a .net project, but now they have put some of use back on PHP projects as we mainly run Apache Servers. AJAX is something I haven't realy looked at in the past as I haven't needed anything other than what you can do in PHP. But I will be taking a good look at it now.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.