douyingyu5573 2017-01-02 16:04
浏览 30
已采纳

邮政编码和检索它们

In this code I want to query a table called "zipcodes". I want to first check to see if the zip code entered is a valid zip code. Then if it is a valid zip code I want to retrieve that zip code with the matching longitude, latitude, city, & state.

Then after retrieving them I want to place them into another table called "Users". Once in Users table I want to be able to pull the values that are assigned to them to echo in various places on my website.

 <?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条回答 默认 最新

  • duanming7961 2017-01-02 18:39
    关注

    This is a quick review of your code. There is no other answer to be made here. My comments begin with // :. I've fixed up the basic syntax and indented the code to make it readable.

    <?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}'");
    }
    

    No magic in the world would make this work -- even with all the syntax corrected. I'd recommend you first spend a bit of time learning PHP (and MySQL) syntax. Then think through the logic of what you want to do. Then try to express that in your code. Start with writing test code for the most simple things. Then work your way up to more complicated stuff. Good luck and happy learning.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路