doudu3961
doudu3961
2015-07-24 05:16

从mysqli获取数据时未定义的变量

  • php

I'm new to php n I'm trying to make a phone to timezone converter. I'm getting the error undefined variable '$result' on line 49 How do I resolve it. Also if you can find out any other mistakes I've made Please chck for errors I'm making Phone number:

    <button type="submit" name="submit" action="submit">
        Submit
    </button>
</form>
    <?php
        $servername = "127.0.0.1";
        $username = "root";
        $password = "";
        $ccode=$_POST["phone"];
            // Create connection
            $db = new mysqli($servername, $username, $password);

            // Check connection
            if ($db->connect_error) {
                die("Connection failed: " . $db->connect_error);
            } 
        $pattern = '/^\(?[\d]{1,4}\)?( |-)?/';
        if(preg_match($pattern, $ccode, $matches))
        {

            $code = $matches[0];
        } else $code = substr($ccode, 0, 4);
        $q = "SELECT nicename FROM country.country WHERE phonecode=$code";
        if($query = $db->query($q)) 
        {
            $record = $query->fetch_assoc();
        } else echo "<br/>NO RECORD";
        echo '<pre>';print_r($record);

        if (empty($_POST["phone"]))
        {
            echo "<p>Please write a Phone Number!</p>";
        }
        $abb = "SELECT zone_id FROM zone INNER JOIN country on country.country_code = zone.country_code
                WHERE country.country_name = " . $record['nicename'];
        if($query = $db->query($abb)) 
        {
            $result = $query->fetch_assoc();
        } else echo "<br/>NO RECORD";
        echo '<pre>';print_r($result);
    ?>
</body>

Thanks for the help!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答