0

I have an html page

<html>
    <head>
    </head>
    <body>
        <form>
            <div><a href="MySubmissionView.php">Number of Applications:</a></div>
            <div><a href="MySubmissionView.php">Submitted Applications:</a></div>
        </form>
    </body>
</html>

and i have a php page 'MySubmissionView.php' for some process. in my php page how i know which link is i have clicked.?thanks in advance

user3789344
  • 81
  • 1
  • 3
  • 14

4 Answers4

2

Add a query string to your hrefs. e.g. MySubmissionView.php?page=number and MySubmissionView.php?page=submitted. You can access the query string from your php with $_GET('paramname'). Here's an example:

HTML:

<html>
    <head>
    </head>
    <body>
        <form>
            <div><a href="MySubmissionView.php?page=number">Number of Applications:</a></div>
            <div><a href="MySubmissionView.php?page=submitted">Submitted Applications:</a></div>
        </form>
    </body>
</html>

PHP:

if (isset($_GET['page']))
  if($_GET['page'] == 'number') {
    // process page number here
  } elseif($_GET['page'] == 'submitted') {
    // process page submitted here
  }
}
Henri Hietala
  • 3,021
  • 1
  • 20
  • 27
  • +1 for the previus comment, and as personal opinion, I would change that `isset()` to `!empty()` – gmo Aug 01 '14 at 09:00
1
<div><a href="MySubmissionView.php?id=xx1">Number of Applications:</a></div>
<div><a href="MySubmissionView.php?id=xx2">Submitted Applications:</a></div>

Php page:

if (!empty($_GET['id'])) {
    echo '<p>The id is: '.$_GET['id'].'</p>';
    // do something else
}
mowgli
  • 2,796
  • 3
  • 31
  • 68
  • Redundant, `empty()` already check if the var is set. [See detailed answer here](http://stackoverflow.com/questions/4559925/why-check-both-isset-and-empty) – gmo Aug 01 '14 at 08:57
1
<html>
    <head>
    </head>
    <body>
        <form>
            <div><a href="MySubmissionView.php?click=1">Number of Applications:</a></div>
            <div><a href="MySubmissionView.php?click=2">Submitted Applications:</a></div>
        </form>
    </body>
</html>

MySubmissionView.php:

if($_GET['click'] == 1){
   echo "first a clicedk";
}else{
    echo "second a clicedk";
}
Raymond Cheng
  • 2,425
  • 21
  • 34
0
<html>
<head>
</head>
<body>
    <form>
        <div><a href="MySubmissionView.php?go=1">Number of Applications:</a></div>
        <div><a href="MySubmissionView.php?go=2">Submitted Applications:</a></div>
    </form>
</body>

Above is your HTML And Your PHP of MySubmissionView.php should look like below.

<?php
     $go = "";
       if(isset($_GET)){
            if(isset($_GET['go'])){
                $go = $_GET['go'];
            }else{
                // do something if '$_GET['go']' is not set
            }
      }else{
        // Do something if u don't get a $_GET Request
      }

    echo 'Clicked Page'.$go;
?>

--

 if(isset($_GET))

Will check the page gets either GET / Post Request. Read about Get / Post Methods

Spider
  • 514
  • 1
  • 10
  • 22