简体   繁体   English

php在多个输入搜索表单上返回空白页

[英]php returning blank pages on multiple input search form

I am brand new to php/mysql and brand new to the site, so thanks ahead for any help. 我是php / mysql的新手,并且是该站点的新手,所以在此先感谢您的帮助。 I need to create a php script which will return results from a search form with four input fields. 我需要创建一个PHP脚本,该脚本将从具有四个输入字段的搜索表单中返回结果。 It needs to be so that any combination of the fields can be searched or none at all which will return all of the items from the database. 必须如此,以便可以搜索字段的任何组合或根本不搜索任何字段,这将返回数据库中的所有项目。 As of now, all that is being returned when I click submit on the form page is a blank page. 到目前为止,单击表单页面上的“提交”时返回的所有内容都是空白页面。

This is what I have so far. 到目前为止,这就是我所拥有的。 I tried it as one query intially which tried to capture all of the requirements, and then as a series of "if" statements, which I read to do on this site, but all I get is a blank page. 我尝试将其作为一个查询来尝试捕获所有需求,然后将其作为一系列“ if”语句进行尝试,我在该站点上进行了阅读,但是得到的只是一个空白页。

<?php
if (isset(
  $_POST['product_description'],$_POST['product_finish'],
  $_POST ['product_minimum_price'], $_POST['product_maximum_price'])) {

    $product_description = ($_POST['product_description']);
    $product_finish = ($_POST['product_finish']);
    $product_minimum_price = ($_POST['product_minimum_price']);
    $product_maximum_price = ($_POST['product_maximum_price']);

    $query = "SELECT ProductDescription, ProductFinish, ProductStandardPrice FROM product_t";
    if (isset($_POST['product_description'])) {
        $query = "SELECT ProductDescription, ProductFinish, ProductStandardPrice
             FROM product_t
             WHERE ProductDescription LIKE '%.$product_description.%'";
    }

    if (isset($_POST['product_finish'])) {
        $query = "SELECT ProductDescription, ProductFinish, ProductStandardPrice
             FROM product_t
             WHERE ProductDescription LIKE '%.$product_finish.%'";
    }

    if (isset($_POST['product_minimum_price'])) {
        $query = "SELECT ProductDescription, ProductFinish, ProductStandardPrice
             FROM product_t
             WHERE ProductStandardPrice >= 'product_minimum_price'";
    }

    if (isset($_POST['product_maximum_price'])) {
        $query = "SELECT ProductDescription, ProductFinish, ProductStandardPrice
             FROM product_t
             WHERE ProductStandardPrice <= 'product_maximum_price'";
    }

    $result = mysql_query($query);
    if($result === FALSE) die(mysql_error());

    echo '<table align="left" cellspacing="1" cellpadding ="5" border="1"><tr><td
    align="left">Product Description</td><td align="left">Product Finish</td><td align="left">
    Product Standard Price</td></tr>';

    while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
        echo '<tr><td align="left">' .$row['ProductDescription'].
        '</td><td align="left">'.$row['ProductFinish'].
        '</td><td align="left">'.$row['ProductStandardPrice'].'</td></tr>';
    }

   echo '</table>';
   mysql_close();
}
?>

If you're getting a blank page it's because your outer if statement isn't evaluating to true. 如果您得到空白页,那是因为您的外部if语句未评估为true。 Include an else clause and echo something else. 包含else子句并回显其他内容。

Chances are you have a form name misspelled, you should have the page only echo those POST variables to double check you're getting data to them. 您的表单名称可能会拼写错误,您应该让页面仅回显那些POST变量,以再次检查是否正在向它们获取数据。

Also, you're missing the connection to the database, I suggest using PDO's as your database connection, you'll get much better error reporting. 另外,您缺少与数据库的连接,我建议使用PDO作为数据库连接,您将获得更好的错误报告。

mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

HTH 高温超导

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM