开发者

php mysql postcode check

开发者 https://www.devze.com 2023-04-01 14:11 出处:网络
Hello I am only starting to learn php can anyone help.I need to be able to check database for delivery postc开发者_开发技巧ode.

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

精彩评论

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