开发者

php mysql postcode check

Hello I am only starting to learn php can anyone help. I need to be able to check database for delivery postc开发者_开发技巧ode.

I have a table called delivery with two columns one is ID and other Postcode.

There will be several pre-recorded postcodes in database. I have an input in a form for user to input postcode. I need to check this postcode with database and if it exists continue if not show error.

Heres what I have so far.

<?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';

}

?>

Please help kinda stuck!!


<?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';

}

This one should work - have a look at the manual page for mysql_fetch_array() for the example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜