PHP HTML Pass Values Through URL

From CoderLearner
Jump to: navigation, search

PHP process data through URL

Processing form data through URL.

Example 1

  • In this example, you pass the value through URL.
<?php
$msg = "";
if (!empty($_GET['option'])) {
   $msg = 'Option is: '
           . $_GET['option']
           . ' and Id is: '
           . $_GET['id'] . '<br/>';
} else {
   $msg = 'Please click your option!<br/>';
}
?>
<html>
   <head>
      <title>Pass value through URL</title>
   </head>
   <body>
      <b><?php echo $msg; ?></b>
      <table border="0">
         <tr>
            <td>Operation 1:</td>
            <td>
               <a href="<?= $_SERVER['PHP_SELF'] ?>?id=1&option=delete">Delete</a>
            </td>
         </tr>
         <tr>
            <td>Operation 2:</td>
            <td>
               <a href="<?= $_SERVER['PHP_SELF'] ?>?id=2&option=update">Update</a>
         </tr>
         <tr>
            <td>Operation 3:</td>
            <td><a href="<?= $_SERVER['PHP_SELF'] ?>?id=3&option=view">View</a>
         </tr>
         <tr>
            <td>Operation 3:</td>
            <td><a href="<?= $_SERVER['PHP_SELF'] ?>?id=4&option=add">Add</a>
         </tr>
      </table>
   </body>
</html>

Try It