Jump to content

What am I doing wrong with this db query?


ballhogjoni

Recommended Posts

I am trying to get a result set from the following code but its not returning any info. Can someone help me out with this? I am passing the following query ("SELECT * FROM Member WHERE " . "username = $username AND " . "password = $password") to dbQuery() from this function:

 

function _checkLogin($username, $password, $remember) {
  $db = new db();
  $sql = "SELECT * FROM Member WHERE " . "username = $username AND " . "password = $password";
  $result = $db->dbQuery($sql);
  print_r($result);
  if (is_object($result)) { 
   $this->_setSession($result, $remember); 
   echo 'redirected';
   return true; 
  } else { 
   $this->failed = true; 
   $this->_logout(); 
   echo 'you\'d not be redirected';
   return false; 
  } 
}

 

<?php
class db {
var $db_host = 'localhost'; 
var $db_user = 'root'; 
var $db_pass = ''; 
var $db_name = 'realfina_allcbreviews';

/* connects to the db */
function db_connect($sql) { 
  $conn = mysql_connect($this->db_host,$this->db_user,$this->db_pass);
  if (!$conn) {
   die('Could not connect: ' . mysql_error());
  }
  mysql_select_db($db_name);
  $results = mysql_query($sql, $conn);
  return $results;
}

/* This gets the info */
function dbQuery($sql) {
  $object = $this->db_connect($sql);
  return $object;
}
}
?>

Ok I added an (or die ) on my statements and it says that no database is selected.

 

This is error is coming from this line of code:

mysql_select_db($db_name, $conn) or die(mysql_error());

 

But the code connects to the db, any ideas?

 

<?php
class db {
var $db_host = 'localhost'; 
var $db_user = 'root'; 
var $db_pass = ''; 
var $db_name = 'realfina_allcbreviews';

/* connects to the db */
function db_connect($sql) { 
  $conn = mysql_connect($this->db_host,$this->db_user,$this->db_pass);
  if (!$conn) {
   die('Could not connect: ' . mysql_error());
  }
  mysql_select_db($db_name, $conn) or die(mysql_error());
  $results = mysql_query($sql, $conn);// or die(mysql_error());
  return $results;
}

/* This gets the info */
function dbQuery($sql) {
  $object = $this->db_connect($sql);
  return $object;
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.