Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DB_Functions {
- private $db;
- function __construct() {
- require_once 'db_connect.php';
- $this->db = new DB_Connect();
- $this->db->connect();
- }
- public function getUser($uid, $password) {
- $result = mysql_query("SELECT * FROM users WHERE id = '$uid' AND pswd = '$password'") or die(mysql_error());
- $no_of_rows = mysql_num_rows($result);
- if ($no_of_rows > 0) {
- $result = mysql_fetch_array($result);
- return $result;
- } else {
- return false;
- }
- }
- }
- ?>
- <?php
- class DB_Functions {
- private $db;
- function __construct() {
- require_once 'db_connect.php';
- $this->db = new DB_Connect();
- $this->db->connect();
- }
- public function getUser($uid, $password) {
- $stmt = $db->prepare("SELECT * FROM users WHERE id=? AND pswd=?");
- $stmt->execute(array($uid, $password));
- return $stmt->fetch();
- }
- }
- ?>
- require_once 'include/db_functions.php';
- $db = new DB_Functions();
- if ($tag == 'login') {
- $uid =mysql_real_escape_string($_POST['id']);
- $password =mysql_real_escape_string($_POST['pswd']);
- // check for user
- $user = $db->getUser($uid, $password);
- if ($user != false) {
- $response["success"] = 1;
- $response["user"]["id"] = $user["id"];
- echo json_encode($response);
- } else {
- $response["error"] = 1;
- $response["error_msg"] = "Incorrect email or password!";
- echo json_encode($response);
- }
- if ($tag == 'login') {
- // check for user
- $user = $db->getUser( $_POST['id'], $_POST['pswd']);
- ... etc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement