-1

如果客户表中已经存在具有相同邮政编码的客户并且如果存在,我尝试检查我的数据库。

我有下面的 PHP 代码,我遇到的问题是。我已经收到回声消息,天气存在或不存在。select_to_array是中的一个功能,config.php它工作正常。

<?php
require("config.php");

    $validate_value = isset($_POST['value']) ? $_POST['value'] : null; 
    $validate_Year =isset($_POST['Year']) ? $_POST['value'] : null; 
    $validate_postcode  = isset($_POST['postcode']) ? $_POST['value'] : null; 
    $select = "SELECT count (*) FROM customers WHERE reg_year= :reg_year 
                 AND reg_code = :reg_name AND reg_value = :reg_value";

                $bind_bb = array(':reg_year' => $validate_Year,
                                    ':reg_code' => $validate_code,
                                    ':reg_value' => $validate_value);


                $validate_result = select_to_array($db_connect,$select, $index, $bind_bb);


        if ($validate_result[0][0] == 0) {  

        echo 'Customer Does not no exist';

        }       
        else {

        echo 'Already exist, please try a different postcode';

        }       
?>
4

1 回答 1

1

You check is incorrect from many points - first you need to know if there's any data, not how much records you have, therefore your SELECT should feature LIMIT 1 as this is pretty much sufficient. As for

if ($validate_result[0][0] == 0) {  

this is not valid too, as if your dataset is empty you will be throwing notices. Replace with

if (empty($validate_result)) {  

or

if (count($validate_result) == 0) {  

also it looks you may have wrong query as this:

':reg_name' => $validate_name,

may look for empty reg_name as $validate_name is not set in your code (while other params are)

于 2013-11-11T09:38:29.453 回答