我不知道这里出了什么问题。
第1步:输入名字和姓氏
第2步:选择日期
第3步:点击提交按钮
结果:显示结果
错误:
注意:未定义的变量:sql in 第20行的C:\ xampp \ htdocs \ xampp \ prive_tc \ testingphp.php
致命错误:函数名称必须是字符串 第20行的C:\ xampp \ htdocs \ xampp \ prive_tc \ testingphp.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("prive_ts", $con);
$sql ("SELECT * from info");
$from = $_get['from']; // or $from = $_get['from'];
$to = $_get['to']; // or $to = $_get['to'];
$sql .= mysql_query(" WHERE date_of_service between '".$from."' AND '".$to."' ");
if (!mysql_query($con,$sql))
{
die('Error: ' . mysql_error($con));
}
?>
<form name="search_form" method="POST" action="testingphp.php">
Search: <input type="text" name="search_box" value="" />
Dates From : <input type="text" name="from"/>
To : <input type="text" name="to"/>
<input type="submit" name="search" value="Look up Patient ...">
</form>
<table width="70%" cellpadding="5" cellspace="5">
<tr>
<td><strong>Care Provider</strong></td>
<td><strong>Patient Name</strong></td>
<td><strong>Date of Time</strong></td>
<td><strong>Time In</strong></td>
<td><strong>Time Out</strong></td>
<td><strong>Remarks</strong></td>
</tr>
<?php while ($row = mysql_fetch_array($query)) { ?>
<tr>
<td><?php echo $row['care_provider']; ?></td>
<td><?php echo $row['patient_name']; ?></td>
<td><?php echo $row['date_of_service']; ?></td>
<td><?php echo $row['time_in']; ?></td>
<td><?php echo $row['time_out']; ?></td>
<td><?php echo $row['remarks']; ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
答案 0 :(得分:2)
然后让我们列出一个清单。
需要分配SQL查询:
$sql = "SELECT * FROM .. ";
连接:
$sql .= mysql_query("...");
需要拆分:
$sql .= "WHERE ...";
然后调用:
$result = mysql_query($sql);
$_GET
变量需要全部大写。
这可能不适合您的体验水平,但请考虑阅读PDO和绑定参数。
答案 1 :(得分:1)
将$sql ("SELECT * from info");
更改为$sql = "SELECT * from info";
您的代码中也存在一些错误。它不会起作用。尝试这样的事情:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("prive_ts", $con);
$sql = "SELECT * from info" ;
$from = $_get['from']; // or $from = $_get['from'];
$to = $_get['to']; // or $to = $_get['to'];
$sql .= " WHERE date_of_service between '".$from."' AND '".$to."'";
$result = mysql_query($sql,$con);
if (!$result)
{
die('Error: ' . mysql_error($con));
}
?>
答案 2 :(得分:1)
更改
$sql ("SELECT * from info");
到
$sql = "SELECT * from info";
并且,为了上帝的缘故,不要在没有验证的情况下将用户输入插入到SQL查询中。首先使用mysqli_real_escape_string
。
答案 3 :(得分:1)
你错过了第20行的=
正确的语法:$sql = "SELECT * from info";
并替换第24行:
$sql .= mysql_query(" WHERE date_of_service between '".$from."' AND '".$to."' ");
with:
$sql .= " WHERE date_of_service between '".$from."' AND '".$to."' ";
建议:
mysql_real_escape_string($keywords);
或strip_tags($keywords)
来阻止sql注入MYSQLI
代替mysql 答案 4 :(得分:0)
$sql ("SELECT * from info");
PHP将此变量视为一个函数,因为您没有使用'='标记并且在引号之间放置了一些内容。 例如:
$variable = "Test";
$variable(); // Outputs an error since the value is a string
您想为变量指定一个字符串。所以你想要做的是:
$sql = "SELECT * from info";