Jump to content

Recommended Posts

This is my menu code on my index.php:
[code]
function menu_case($selected)
{
    switch($selected)
    {
        case 0:
            echo add_product_form();
            break;
        case 1:
            echo find_products();
            break;
        default:
            echo find_products();
            break;
    }
}
[/code]
When the page loads I have find_products() as a default value, on the same page I have a "Add Product" which will link to a function, how can I do that?

I have tried doing this but I get an error:

[code]
<a href='<? menu_case(0) ?>' class='style10'>Add Product</a> | Add  Category<br><HR></td>
[/code]

Note that my add_product_form() contains a form which be displayed on the same page.
Link to comment
https://forums.phpfreaks.com/topic/6163-calling-a-function-from-a-link/
Share on other sites

Php runs on the server so cant be directly called from links (like javascript), but there are ways....

An example...
[code]
<?php

  if (isset($_GET['action'])) {
    switch ($_GET['action']) {
      case "foo":
        foo();
      break;
      case "bar";
        bar();
      break;
    }
  }

  function foo() {
    echo "this is foo\n";
  }

  function bar() {
    echo "this is bar\n";
  }

?>

<a href="?action=foo">call foo</a>
<a href="?action=bar">call bar</a>
[/code]
Hope this helps.
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.