ballhogjoni Posted July 14, 2008 Share Posted July 14, 2008 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; } } ?> Link to comment https://forums.phpfreaks.com/topic/114589-what-am-i-doing-wrong-with-this-db-query/ Share on other sites More sharing options...
DyslexicDog Posted July 14, 2008 Share Posted July 14, 2008 You have some misplaced commas in your sql statement. "SELECT * FROM Member WHERE " . "username = $username AND " . "password = $password"; should be "SELECT * FROM member WHERE username = \"". $username ."\" AND password = \"". $password."\""; Link to comment https://forums.phpfreaks.com/topic/114589-what-am-i-doing-wrong-with-this-db-query/#findComment-589198 Share on other sites More sharing options...
ballhogjoni Posted July 14, 2008 Author Share Posted July 14, 2008 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; } } ?> Link to comment https://forums.phpfreaks.com/topic/114589-what-am-i-doing-wrong-with-this-db-query/#findComment-589215 Share on other sites More sharing options...
ballhogjoni Posted July 14, 2008 Author Share Posted July 14, 2008 I figured my last question out, I forgot to add $this-> to the mysql_select_db() Link to comment https://forums.phpfreaks.com/topic/114589-what-am-i-doing-wrong-with-this-db-query/#findComment-589219 Share on other sites More sharing options...
vicodin Posted July 14, 2008 Share Posted July 14, 2008 triple check your user name and pass, you shouldnt need to $conn in the mysql_select_db, not sure if that will fix anything but give it a shot. Link to comment https://forums.phpfreaks.com/topic/114589-what-am-i-doing-wrong-with-this-db-query/#findComment-589224 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.