drex88669 2013-04-17 02:47
浏览 24
已采纳

关于用户拒绝访问的PHP错误消息(使用密码:否)

my php version is 5.2, which is the old verison. it is because i use the free server it is my website http://driverrecord.hostzi.com/android_login_api/include/profile.php?username=4

i hope someone can help me. the problem may be about the code.

the error message:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'a6578726'@'localhost' (using password: NO) in /home/a6578726/public_html/android_login_api/include/profile.php on line 20

profile.php

 // array for JSON response
 $response = array();

 // include db connect class
 require_once dirname(__FILE__). '/DB_Connect.php';

 // connecting to db
 $db = new DB_CONNECT();


 // check for post data
 if (isset($_GET["username"])) {

     $username = $_GET['username'];

     // get a product from products table
    $result = mysql_query("SELECT * FROM user WHERE user_id = $username");

     if (!empty($result)) {
         // check for empty result
         if (mysql_num_rows($result) > 0) {

             $result = mysql_fetch_array($result);

             $username = array();
           $username["username"] = $result["user_id"];
           $username["first_name"] = $result["first_name"];
           $username["last_name"] = $result["last_name"];
        $username["email"] = $result["email"];
        $username["tel"] = $result["tel"];
        $username["age"] = $result["age"];
        $username["gender"] = $result["gender"];
        // success
        $response["success"] = 1;

        // user node
         $response["username"] = array();

         array_push($response["username"], $username);

        // echoing JSON response
         echo json_encode($response);
      } else {
         // no product found
         $response["success"] = 0;
         $response["message"] = "No product found";

         // echo no users JSON
         echo json_encode($response);
       }
     } else {
      // no product found
      $response["success"] = 0;
       $response["message"] = "No product found";

    // echo no users JSON
    echo json_encode($response);
  }
  } else {
    // required field is missing
    $response["success"] = 0;
   $response["message"] = "Required field(s) is missing";

  // echoing JSON response
  echo json_encode($response);


  }
   ?>

DB_Connect.php

 class DB_Connect {

    // constructor
   function __construct() {

  }

  // destructor
  function __destruct() {
      // $this->close();
  }

    // Connecting to database
    public function connect() {
        require_once 'include/config.php';
         // connecting to mysql
          $con = mysql_connect("XXXXXwebhost.com", "a6578726_driver", "abcde");
       // selecting database
       mysql_select_db(DB_DATABASE);

      // return database handler
      return $con;
    }

  // Closing database connection
  public function close() {
    mysql_close();
  }

 }

 ?>

config.php

   <?php
  /**
   * Database config variables
   */
 define("DB_HOST", "XXXXwebhost.com");
  define("DB_USER", "a6578726_driver");
  define("DB_PASSWORD", "abcde");
  define("DB_DATABASE", "a6578726_driver");
  ?>
  • 写回答

2条回答 默认 最新

  • duanchuang6978 2013-04-17 02:52
    关注

    Creating a DB_Connect object is not sufficient to connect to the database. Call connect() on that object to connect to the database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失