我正在预约管理网站上工作。我已经设计了一个页面来安排约会(插入数据库)并且工作正常。现在我想查看现有的约会(从数据库中查看/获取),甚至可以根据需要进行修改(更新)。我在现有的约会中面临错误。
这是现有约会的代码:
<?php
mysql_connect("localhost", "root", "") or die("Could not connect.");
mysql_select_db("appointo") or die("could not find db.");
if(isset($_POST['uname'])){
$searchq = $_POST['uname'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = mysql_query("SELECT * FROM appointments WHERE username LIKE '$searchq'") or die("could not search.");
$count = mysql_num_rows($query);
while($row = mysql_fetch_array($query)){
$name = $row['name'];
$doctorname = $row['doctorname'];
$purpose = $row['purpose'];
//$oname = '<div>'.$name.'</div>';
//$odname = '<div>'.$doctorname.'</div>';
//$opurpose = '<div>'.$purpose.'</div>';
}
}
?>
<form method="POST">
<input type="text" name="uname" placeholder="Seach using Name.." />
<input type="search" name="search" value="Search" /><br><br>
Output:
<?php
//$name=$_SESSION['name'];
//$doctorname=$_SESSION['doctorname'];
//$purpose=$_SESSION['purpose'];
echo "'Name:''.$name'";
echo "Doctor Name:".$doctorname;
echo "Purpose:".$purpose;
?>
</form>
仍然无法获取数据。 我希望如果有人输入我已经存储在我的数据库中的用户名(例如,nichani)。点击搜索按钮,他应该在下面看到输出:
姓名:Nishant Nichani
医生姓名:A。博士
目的:一般检查
答案 0 :(得分:0)
您应该在表单中添加uname输入字段。
你应该检查一下 表单已提交或只是第一次加载页面。
您还应检查空结果。
要进行LIKE
搜索,您应该使用%
指定任何长度的字符串。
mysql_select_db("appointo") or die("could not find db.");
if(isset($_POST['uname'])){
$searchq = $_POST['uname'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = mysql_query("SELECT * FROM appointments WHERE username LIKE '%$searchq%'") or die("could not search.");
$count = mysql_num_rows($query);
while($row = mysql_fetch_array($query)){
$name = $row['name'];
$doctorname = $row['doctorname'];
$purpose = $row['purpose'];
//$oname = '<div>'.$name.'</div>';
//$odname = '<div>'.$doctorname.'</div>';
//$opurpose = '<div>'.$purpose.'</div>';
}
}
?>
<form method="POST">
Uname:
<input name="uname" value="<?php echo @$_POST['uname']; ?>" placeholder="search name"/>
Output:
<?php
//$name=$_SESSION['name'];
//$doctorname=$_SESSION['doctorname'];
//$purpose=$_SESSION['purpose'];
if(isset($_POST['uname'])){
if(!empty(isset($query))){
echo "'Name:''.$name'";
echo "Doctor Name:".$doctorname;
echo "Purpose:".$purpose;
}else{
echo "NOT FOUND";
}
}
?>
</form>
答案 1 :(得分:0)
在输入if语句之前定义空白变量,如 $ doctorname =&#39;&#39 ;; $ purpose =&#39;&#39 ;; 它应该让你的工作完成。