(PHP)在php文件中编写表单

时间:2017-11-14 18:05:40

标签: php html forms session post

我在php文件中编写了一个表单,并使用post方法将值发送到下一页。但是变量不会发送到下一页。我做错了什么?

在下面的代码中,我无法获得帖子值。它说$ 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'");

1 个答案:

答案 0 :(得分:2)

使用代码而不是创建提交按钮

<强>代码

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

而不是

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

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