邮编和附件检索它们

时间:2017-01-02 16:04:00

标签: php mysql

在这段代码中,我想查询名为" zipcodes"的表。我想首先检查输入的邮政编码是否是有效的邮政编码。然后,如果它是有效的邮政编码,我想检索具有匹配的经度,纬度,城市和&的邮政编码。状态。

然后在检索它们之后,我想将它们放入另一个名为" Users"的表中。进入用户表后,我希望能够提取分配给他们的值,以便在我网站的不同位置回显。

 <?php

    $query = mysqli_query($con, "SELECT * FROM zipcodes WHERE ZIP='".$user_zip."'");

    if(mysqli_num_rows($query) > 0){

        echo "Please Reenter A Valid Zip Code";
        {

        }elseif(mysqli_num_rows($query) > 1){
       mysqli
        // Need to put next line of code in users db
          }elseif (mysqli_num_rows($query) > 1($con, "INSERT INTO ")){





        // retrieve from the database the city and state
    }elseif ($user_zip == true( $query = mysqli_query($con, "SELECT * FROM zipcodes ZIP,Latitude,Longitude,City,State WHERE  ZIP='".$zip.", Latitude='".$latitude"', Longitude='".$longitude"', City='".$local"', State='".$country"', "'")) {


    {


    }   


    ?>

1 个答案:

答案 0 :(得分:0)

这是对您的代码的快速回顾。这里没有其他答案。我的评论以// :开头。我修复了基本语法并缩进代码以使其可读。

<?php

$query = mysqli_query($con, "SELECT * FROM zipcodes WHERE ZIP='".$user_zip."'");

// : Checking if there are 0 or more rows returned.
if(mysqli_num_rows($query) > 0) {
    echo "Please Reenter A Valid Zip Code";
// } << : Need a closing bracket here.

{ // : These curlies must be for decorative purposes?
}

// : "If 0 or more rows; else if 1 or more rows". 
// : This'd never run because a previous condition matches; 1 > 0!
elseif(mysqli_num_rows($query) > 1) {
    mysqli
    // Need to put next line of code in users db
}

// : You already matched the > 1 condition above. + syntax error!
elseif (mysqli_num_rows($query) > 1($con, "INSERT INTO ")) {

// : Fixing that syntax. You probably meant something like:

elseif (mysqli_num_rows($query) > 1) {
    mysqli($con, "INSERT INTO [...] ");
}

// : This is totally garbled up, both the PHP and the SQL query:

// retrieve from the database the city and state
/* 
elseif ($user_zip == true( $query = mysqli_query($con, "SELECT * FROM zipcodes ZIP,Latitude,Longitude,City,State WHERE  ZIP='".$zip.", Latitude='".$latitude"', Longitude='".$longitude"', City='".$local"', State='".$country"', "'")) { 
*/

// : You probably meant something like:

elseif ($user_zip == true) {
    $query = mysqli_query($con, 
        "SELECT * FROM zipcodes 
            WHERE ZIP='{$zip}' 
                AND Latitude='{$latitude}' 
                AND Longitude='{$longitude}' 
                AND City='{$local}' 
                AND State='{$country}'");
}

即使修正了所有语法,世界上也没有任何魔法可以使其发挥作用。我建议你先花点时间学习PHP(和MySQL)语法。然后思考你想做什么的逻辑。然后尝试在您的代码中表达它。首先为最简单的事情编写测试代码。然后按照自己的方式处理更复杂的事情。祝你好运,快乐学习。