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

2
  • 5
    Add a query string. e.g. MySubmissionView.php?page=number and MySubmissionView.php?page=submitted Commented Aug 1, 2014 at 6:28
  • @HenriHietala you should post it as an answer Commented Aug 1, 2014 at 6:30

4 Answers 4

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
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for the previus comment, and as personal opinion, I would change that isset() to !empty()
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
}

1 Comment

Redundant, empty() already check if the var is set. See detailed answer here
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";
}

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.