php mysql邮政编码检查

时间:2011-08-30 16:17:35

标签: php mysql forms

你好我只是开始学习php可以任何人帮忙。我需要能够检查数据库的交付邮政编码。

我有一个名为delivery的表,有两列,一列是ID和其他邮政编码。

数据库中会有几个预先录制的邮政编码。我有一个表单输入供用户输入邮政编码。我需要用数据库检查这个邮政编码,如果没有显示错误,它是否存在继续。

到目前为止我所拥有的。

<?php
include 'mysql_connect.php';

if(isset($_POST['submit'])){

        $postcodeQuery = sprintf("SELECT `Postcode` FROM delivery WHERE Postcode = '%s' LIMIT 1",
                    mysql_real_escape_string($_POST['inputPostcode']));

        $postcodeResult = mysql_query($postcodeQuery);
        $delivery           = mysql_fetch_array($postcodeResult, MYSQLI_ASSOC);

        if ($_POST['inputPostcode'] == 'postcode')

        echo 'We deliver to your area'.($_POST['postcode']);

        } else{

        echo 'We do not deliver to your area';

}

?>

请帮助有点卡住!!

1 个答案:

答案 0 :(得分:1)

<?php
include 'mysql_connect.php';

if(isset($_POST['submit'])) {
        echo 'Please enter an email address';

        $postcodeQuery = sprintf("SELECT `Postcode` FROM delivery WHERE Postcode = '%s' LIMIT 1",
                    mysql_real_escape_string($_POST['inputPostcode']));

        $postcodeResult = mysql_query($postcodeQuery);
        $delivery       = mysql_fetch_array($postcodeResult, MYSQLI_ASSOC);

        if ($_POST['inputPostcode'] == $delivery[0])
            echo 'We deliver to your area '.($_POST['postcode']);
        else
            echo 'We do not deliver to your area';

}

这个应该可行 - 请查看示例的mysql_fetch_array()手册页。