我需要一个表格,其条件是fullyy = $ddate
如何获取ddate
文本框的值并将其放入我拥有的变量$ddate
。我需要在同一页面中使用此代码:
//php
$ddate = "";
if (isset($_POST['ddate']))
{ $ddate = $_POST['ddate'];
$result = mysql_query("SELECT * FROM tblnpatient WHERE fullyy = '$ddate'");
while($row = mysql_fetch_array($result)){
echo '<tr>';
echo '<td>'.$row['pnum'].'</td>';
echo '<td>'.$row['pname'].'</td>';
echo '<td>'.$row['addr'].'</td>';
}}
这是我的html,ddate
的值来自脚本:
Diff:<input name="ddate" id="ddate" />
我的页面没有结果,我的代码出了什么问题?
答案 0 :(得分:0)
您必须使用表单。看起来应该是这样的:
<?php
$ddate = "";
if (isset($_POST['ddate'])){
$ddate = $_POST['ddate'];
}
?>
您应该使用mysqli_
代替mysql_
:
<?php
$results = mysqli_query($connection, $query);
while ($row = mysqli_fetch_assoc($results)){
echo "<br/>";
echo $row["name"];
}
mysqli_free_result($result);
?>
您的表单应如下所示:
<form action="samefile.php" method="post">
Diff:<input type="text" name="ddate" id="ddate" onchange"this.form.submit()"/>
</form>