barkster Posted July 17, 2007 Share Posted July 17, 2007 I am trying to use this db class here http://www.micahcarrick.com/v2/content/view/3/26/ and I get cannot modify header information when I try and use the class for login. I've stripped everything out of th the class that I would think would send header and still get the error. Throws error when I try and redirect the user. <?php if($_POST['blogin']) { require_once('bb.db.class.php'); $db = new db_class; if (!$db->connect("localhost", "user", "pw", "db", true)){ echo("Could not connect to database"); die(); } $r = $db->select_two("SELECT UserID, Username FROM Users WHERE Username='" . $_POST['tbusername']. "' AND Password='".$_POST['tbpassword']."' AND Banned='0'"); if($r) { $userid = $r[0]; $username = $r[1]; echo $userid; echo $username; $_SESSION['UserID']=$userid; $_SESSION['Username']=$username; header("Location: Success.php"); die(); } else { $msg = "We could not verify your login information, please try again"; } } ?> stripped class <?php define('MYSQL_TYPES_NUMERIC', 'int real '); define('MYSQL_TYPES_DATE', 'datetime timestamp year date time '); define('MYSQL_TYPES_STRING', 'string blob '); class db_class { var $last_error; // holds the last error. Usually mysql_error() var $last_query; // holds the last query executed. var $row_count; // holds the last number of rows from a select var $host; // mySQL host to connect to var $user; // mySQL user name var $pw; // mySQL password var $db; // mySQL database to select var $db_link; // current/last database link identifier var $auto_slashes; // the class will add/strip slashes when it can function db_class() { // class constructor. Initializations here. // Setup your own default values for connecting to the database here. You // can also set these values in the connect() function and using // the select_database() function. //localhost", "shrinkup_barkste", "bb2828", "shrinkup_shrink $this->host = 'localhost'; $this->user = ''; $this->pw = ''; $this->db = ''; $this->auto_slashes = true; } function connect($host='', $user='', $pw='', $db='', $persistant=true) { // Opens a connection to MySQL and selects the database. If any of the // function's parameter's are set, we want to update the class variables. // If they are NOT set, then we're giong to use the currently existing // class variables. // Returns true if successful, false if there is failure. if (!empty($host)) $this->host = $host; if (!empty($user)) $this->user = $user; if (!empty($pw)) $this->pw = $pw; // Establish the connection. if ($persistant) $this->db_link = mysql_pconnect($this->host, $this->user, $this->pw); else $this->db_link = mysql_connect($this->host, $this->user, $this->pw); // Check for an error establishing a connection if (!$this->db_link) { //$this->last_error = mysql_error(); return false; } // Select the database if (!$this->select_db($db)) return false; return $this->db_link; // success } function select_db($db='') { // Selects the database for use. If the function's $db parameter is // passed to the function then the class variable will be updated. if (!empty($db)) $this->db = $db; if (!mysql_select_db($this->db)) { //$this->last_error = mysql_error(); return false; } return true; } function select_two($sql) { // Performs an SQL query with the assumption that only ONE column and // one result are to be returned. // Returns the one result. $r = mysql_query($sql); if (!$r) { //$this->last_error = mysql_error(); return false; } $one = mysql_result($r, 0, 0); $two = mysql_result($r, 0, 1); $ret = array($one,$two); //mysql_free_result($r); return $ret; } } ?> Link to comment https://forums.phpfreaks.com/topic/60402-mysql-database-class/ Share on other sites More sharing options...
trq Posted July 17, 2007 Share Posted July 17, 2007 Make sure there is no white space before your <?php tags. Also... you cannot output ANY data prior to calling the header function, you'll need to remove... echo $userid; echo $username; Link to comment https://forums.phpfreaks.com/topic/60402-mysql-database-class/#findComment-300484 Share on other sites More sharing options...
barkster Posted July 17, 2007 Author Share Posted July 17, 2007 I look for white space, I added the echo to make sure it was getting into that if statement. Link to comment https://forums.phpfreaks.com/topic/60402-mysql-database-class/#findComment-300498 Share on other sites More sharing options...
barkster Posted July 17, 2007 Author Share Posted July 17, 2007 Ok, removed the require_once('bb.db.class.php'); and replaced it with the code from the class and it works. I checked for whitespace and didn't see any. This is weird. Link to comment https://forums.phpfreaks.com/topic/60402-mysql-database-class/#findComment-300504 Share on other sites More sharing options...
trq Posted July 17, 2007 Share Posted July 17, 2007 Did you remove the echo's? As I said, you cannot have ANY output prior to calling the header function. Link to comment https://forums.phpfreaks.com/topic/60402-mysql-database-class/#findComment-300508 Share on other sites More sharing options...
barkster Posted July 17, 2007 Author Share Posted July 17, 2007 Yes, I got it to work by copying the class into a new file and making a simpler name. Never had that happen before, I know what causes it but I couldn't figure out what was going on here. There must have been something goofy in the file. Link to comment https://forums.phpfreaks.com/topic/60402-mysql-database-class/#findComment-300526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.