0

I have written a form inside a php file and used post method to send the value to next page. however the variable is not sent to next page. What am I doing wrong?

In the code below I can't get the post value. It says $dbid undefined!

echo '<table width = "30%" cellpadding = "2" cellspacing ="2" border = "2px">
echo '<table width = "30%" cellpadding = "2" cellspacing ="2" border = "2px">
  <tr>
    <form action="sample.php" method="POST">
      <td> <input  type="text" name="dbid" value='.$row['ID'].' size="4" readonly ></td>
           <button  type="submit" name="submit" >view form</button>
    </form>
  <td>'.$row['username'].'</td>
  <td>'.$row['ecno'].'</td>
  <td>'.$row['division'].'</td>
  <td>'.$row['code'].'</td>
  <td>'.$row['doj'].'</td>
  <td>'.$row['dor'].'</td>
  <td>'.$row['fc'].'</td>
  <td>'.$row['tc'].'</td>
</tr>

Sample.php:

<?php
$dbid= $_POST['dbid'];

$db = mysqli_connect("localhost", "root", "", "logindb1");
if (mysqli_connect_errno())
{
  echo "something went wrong with the connection" . mysqli_connect_error();
 }
echo ' <input type="hidden" name="dbid" value="'.$_POST['dbid'].'"> '; 
$query = mysqli_query($db,"SELECT * FROM users2  WHERE ID ='$dbid'");
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • 1
    Firstly please fix your HTML - it is horrible and invalid. Also never name anything name="submit - it hides the form's submit event. – mplungjan Nov 14 '17 at 18:08

1 Answers1

2

Use tag instead of to create submit button

Code

<input type="submit" name="submit" >view form</button>

Instead of

<button  type="submit" name="submit" >view form</button>

Reference : stackoverflow.com/questions/3543615/difference-between-input-type-submit-and-button-type-submittext-butto

H. Sodi
  • 540
  • 2
  • 9