PHP mysql查询返回一个空白屏幕
我已经注释掉了底部部分,SQL查询工作正常。我相信,这是显示错误来源的查询。PHP mysql查询返回一个空白屏幕,php,mysql,sql,Php,Mysql,Sql,我已经注释掉了底部部分,SQL查询工作正常。我相信,这是显示错误来源的查询。 $host = "127.0.0.1"; $user = "root"; $pass = "Toom13371!"; $connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>"); // 2. Selecting DB. $dbname = "filters";
$host = "127.0.0.1";
$user = "root";
$pass = "Toom13371!";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
// 2. Selecting DB.
$dbname = "filters";
mysql_select_db($dbname);
// 3. Build/Test SQL Query
$sql = ("select * from filter_bandpass where start_passband=" . $_POST['Lowfreq'] . " and stop_passband='" . $_POST['Highfreq'] . "'");
//echo $sql; //Comment/Uncomment to test sql query.
// 4. Retrieve info from MySQL.
$query = mysql_query($sql);
// 5. Display Query.
echo "<table border='1'>
<tr>
<th>Low Frequency</th>
<th>High Frequency</th>
</tr>";
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>" . $row['Lowfreq'] . "</td>";
echo "<td>" . $row['Highfreq'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
$host=“127.0.0.1”;
$user=“root”;
$pass=“toom1371!”;
$connection=mysql\u connect($host,$user,$pass)或die(mysql\u errno()。“:”.mysql\u error()。“
”;
// 2. 选择DB。
$dbname=“过滤器”;
mysql\u select\u db($dbname);
// 3. 构建/测试SQL查询
$sql=(“从滤波器带通中选择*,其中开始带通=“.$\u POST['Lowfreq']”和停止带通=“$\u POST['Highfreq'].”);
//echo$sql//注释/取消注释以测试sql查询。
// 4. 从MySQL检索信息。
$query=mysql\u查询($sql);
// 5. 显示查询。
回声“
低频
高频
";
while($row=mysql\u fetch\u array($query)){
回声“;
回显“$row['Lowfreq']”;
回显“$row['Highfreq']”;
回声“;
}
回声“;
?>
任何帮助都将不胜感激,我相信这将是我忽略的一些小错误
提前感谢:)换行
mysql_select_db($dbname);
mysql_select_db($dbname);
到
也是在查询检查之前
$\u POST['Lowfreq']
和$\u POST['Highfreq']
如果这些变量中没有值,查询将必须返回空。根据您的查询,我猜您需要更改此值 到 及
while($row=mysql\u fetch\u array($query)){
回声“;
回显“$row['Lowfreq']”;
回显“$row['Highfreq']”;
回声“;
}
到
while($row=mysql\u fetch\u array($query)){
回声“;
回显“$row['start_passband']”;
echo“$row['stop_passband']”;
回声“;
}
在查询中,字符串不应包含括号
$sql = ("select * from filter_bandpass where start_passband=" . $_POST['Lowfreq'] . " and stop_passband='" . $_POST['Highfreq'] . "'");
应该是:
$sql = "select * from filter_bandpass where start_passband=" . $_POST['Lowfreq'] . " and stop_passband='" . $_POST['Highfreq'] . "'";
这看起来非常不安全。您确定您的用户参数正确吗
$\u POST
数据不应直接进入查询mysql\u query
是一个过时的接口,不应在新的应用程序中使用,并将在未来的PHP版本中删除。一个现代的替代品。如果你是PHP新手,像这样的指南可以帮助你解释最佳实践。嗨,谢谢你的回答!将研究PDO。@thomasward1212-在stackoverflow上接受给定答案的答案是一个很好的实践。请选择一个答案我现在得到的是表格的顶部,这一位;回波“低频-高频”;但不是查询生成的部分。
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>" . $row['Lowfreq'] . "</td>";
echo "<td>" . $row['Highfreq'] . "</td>";
echo "</tr>";
}
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>" . $row['start_passband'] . "</td>";
echo "<td>" . $row['stop_passband'] . "</td>";
echo "</tr>";
}
$sql = ("select * from filter_bandpass where start_passband=" . $_POST['Lowfreq'] . " and stop_passband='" . $_POST['Highfreq'] . "'");
$sql = "select * from filter_bandpass where start_passband=" . $_POST['Lowfreq'] . " and stop_passband='" . $_POST['Highfreq'] . "'";