-1

I am trying to get the value of two text boxes through GET method. But when i try to print them both. I am not able to do it. The code works perfectly when i do it with single text box.

<?php
if(isset($_GET['name']) && isset($_GET['id']))
{

$username = $_GET['name'];
$userid = $_GET['id'];
echo 'Hi '.$username.'<br>';
echo "Emp Id is ".$userid;
}
?>

<form action="contact-DB.php" method="GET">
Enter Employee Name : <input type = "text" name = "name"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Enter Employee ID : <input type = "text" name = "id">
<input type = "button" name="submit" value="Submit">
Lorenzo Belfanti
  • 1,205
  • 3
  • 25
  • 51

2 Answers2

1

When you are submiting a form there should be a submit button. In your case there is no submit button. That's why the form never submitted.

Please try below example:

<!DOCTYPE html>
<html>
    <body>
        <?php
            if(isset($_GET['name']) && isset($_GET['id']))  {

                $username = $_GET['name'];
                $userid = $_GET['id'];
                echo 'Hi '.$username.'<br>';
                echo "Emp Id is ".$userid;
            }
        ?>
        <form action="contact-DB.php" method="GET">
            Enter Employee Name : 
            <input type = "text" name = "name">
            <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            Enter Employee ID : 
            <input type = "text" name = "id">
            <input type = "submit" name="submit" value="Submit">
        </form>
    </body>
</html>

In your case the form never submitted because

<input type = "button" name="submit" value="Submit">
Dinesh Patra
  • 1,125
  • 12
  • 23
0
<input type="button" /> buttons will not submit a form - they don't do anything by default. They're generally used in conjunction with JavaScript as part of an AJAX application.

<input type="submit"> buttons will submit the form they are in when the user clicks on them, unless you specify otherwise with JavaScript.

so use this

 <input type="submit"  value="Submit" name="submit">
Mohd Zubair Khan
  • 263
  • 2
  • 16