cheechm Posted October 12, 2007 Share Posted October 12, 2007 Can't seem to get this to work: index.php <?php //////////////////////////////////////////////////////////////////////////////////////// // Class: Index // Purpose: The main page of the site /////////////////////////////////////////////////////////////////////////////////////// require_once 'includes/functions.php'; //*** Function: Define variables, Purpose: Make life easier *** $con = new DbConnect(); session_start(); //Checks if there is a login cookie if(isset($_COOKIE[".SITE_NAME."])) if(!isset($username) | !isset($password)) { //check if they are logged in //if there is, it logs you in and directes you to the members page { $username = $_COOKIE[".SITE_NAME."]; $pass = $_COOKIE[".SITE_NAME."]; $check = mysql_query("SELECT * FROM ".TBL_USERS." WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { $this->session_status==True; header("Location: index.php"); } } } } //start constructing the page echo SITE_NAME; echo "<br>"; // Use the query function of DbConnect to run a database query $result = $con->query('SELECT * FROM ".TBL_ARTICLES."'); // Get the result $row = $con->fetchArray($result); // Show it to the user echo $row['articletext']; $con->close(); ?> functions.php <?php //////////////////////////////////////////////////////////////////////////////////////// // Class: Functions // Purpose: Contains all the functions the user may need /////////////////////////////////////////////////////////////////////////////////////// require 'config.php'; class DBConnect extends SystemComponent { var $theQuery; var $link; //*** Function: DbConnector, Purpose: Connect to the database *** function DbConnect(){ // Load settings from parent class $settings = SystemComponent::getSettings(); // Get the main settings from the array we just loaded $host = $settings['dbhost']; $db = $settings['dbname']; $user = $settings['dbusername']; $pass = $settings['dbpassword']; // Connect to the database $this->link = mysql_connect($host, $user, $pass); @mysql_select_db($db, $this); register_shutdown_function(array(&$this, 'close')); } //*** Function: query, Purpose: Execute a database query *** function query($query) { $this->theQuery = $query; return @mysql_query($query, $this->link); } //*** Function: fetchArray, Purpose: Get array of query results *** function fetchArray($result) { return @mysql_fetch_array($result); } //*** Function: close, Purpose: Close the connection *** function close() { @mysql_close($this->link); } } ?> I have checked. It can connect to the DB. However I can't seem to pull the article text from the DB. Anyone see why? Thanks Please use code tags for large amounts of code. Use PHP tags for small snippets of code Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/ Share on other sites More sharing options...
MmmVomit Posted October 12, 2007 Share Posted October 12, 2007 Start getting rid of all the @ signs in front of the mysql functions and start adding "or die(mysql_error())" at the end of them. Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-368236 Share on other sites More sharing options...
zGrassman Posted October 12, 2007 Share Posted October 12, 2007 //Checks if there is a login cookie if(isset($_COOKIE[".SITE_NAME."])) if(!isset($username) | !isset($password)) { //check if they are logged in you are missing an open bracket at the start of your first if Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-368238 Share on other sites More sharing options...
cheechm Posted October 12, 2007 Author Share Posted October 12, 2007 Gives the warning: Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in includes/functions.php on line 28 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-368239 Share on other sites More sharing options...
cheechm Posted October 13, 2007 Author Share Posted October 13, 2007 Anyone else? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-368600 Share on other sites More sharing options...
cheechm Posted October 14, 2007 Author Share Posted October 14, 2007 Bump Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-368903 Share on other sites More sharing options...
corbin Posted October 14, 2007 Share Posted October 14, 2007 if(!isset($username) | !isset($password)) { //check if they are logged in | is a bit operator.... I think you mean ||. mysql_select_db($db, $this); That should be: mysql_select_db($db, $this->link); Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-368912 Share on other sites More sharing options...
cheechm Posted October 14, 2007 Author Share Posted October 14, 2007 Ok changed that however still no results. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-369194 Share on other sites More sharing options...
cheechm Posted October 14, 2007 Author Share Posted October 14, 2007 *Bump* Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-369440 Share on other sites More sharing options...
BlueSkyIS Posted October 14, 2007 Share Posted October 14, 2007 mysql_select_db($db, $this); should be mysql_select_db($db, $this->link); Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-369456 Share on other sites More sharing options...
cheechm Posted October 14, 2007 Author Share Posted October 14, 2007 mysql_select_db($db, $this); should be mysql_select_db($db, $this->link); Said that above.. But thanks anway for looking. Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-369479 Share on other sites More sharing options...
SirChick Posted October 14, 2007 Share Posted October 14, 2007 show the code at its present moment plus any errors you get in return... Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-369482 Share on other sites More sharing options...
cheechm Posted October 14, 2007 Author Share Posted October 14, 2007 index.php: <?php //////////////////////////////////////////////////////////////////////////////////////// // Class: Index // Purpose: The main page of the site /////////////////////////////////////////////////////////////////////////////////////// require_once 'includes/functions.php'; //*** Function: Define variables, Purpose: Make life easier *** $con = new DbConnect(); session_start(); //Checks if there is a login cookie if(isset($_COOKIE[".SITE_NAME."])) if(!isset($username) || !isset($password)) { //check if they are logged in //if there is, it logs you in and directes you to the members page { $username = $_COOKIE[".SITE_NAME."]; $pass = $_COOKIE[".SITE_NAME."]; $check = mysql_query("SELECT * FROM ".TBL_USERS." WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { $this->session_status==True; header("Location: index.php"); } } } } //start constructing the page echo SITE_NAME; echo "<br>"; // Use the query function of DbConnect to run a database query $result = $con->query("SELECT * FROM articles"); // Get the result $row = $con->fetchArray($result); // Show it to the user echo $row['articletext']; $con->close(); ?> functions.php: <?php //////////////////////////////////////////////////////////////////////////////////////// // Class: Functions // Purpose: Contains all the functions the user may need /////////////////////////////////////////////////////////////////////////////////////// require 'config.php'; class DBConnect extends SystemComponent { var $theQuery; var $link; //*** Function: DbConnector, Purpose: Connect to the database *** function DbConnect(){ // Load settings from parent class $settings = SystemComponent::getSettings(); // Get the main settings from the array we just loaded $host = $settings['dbhost']; $db = $settings['dbname']; $user = $settings['dbusername']; $pass = $settings['dbpassword']; // Connect to the database $this->link = mysql_connect("$host", "$user", "$pass"); mysql_select_db("$db", $this->link)or die(mysql_error()); register_shutdown_function(array(&$this, 'close')); } //*** Function: query, Purpose: Execute a database query *** function query($query) { $this->theQuery = $query; return mysql_query($query)or die(mysql_error()); } //*** Function: fetchArray, Purpose: Get array of query results *** function fetchArray($result) { return mysql_fetch_array($result)or die(mysql_error()); } //*** Function: close, Purpose: Close the connection *** function close() { mysql_close($this->link); } } Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /includes/functions.php on line 44 Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-369488 Share on other sites More sharing options...
BlueSkyIS Posted October 14, 2007 Share Posted October 14, 2007 maybe in fetcharray(), echo $result and see what it is? Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-369498 Share on other sites More sharing options...
cheechm Posted October 14, 2007 Author Share Posted October 14, 2007 It echoes "1" which is the article ID. (The first column of the table) Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-369509 Share on other sites More sharing options...
cheechm Posted October 16, 2007 Author Share Posted October 16, 2007 Bump Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-370806 Share on other sites More sharing options...
cheechm Posted October 16, 2007 Author Share Posted October 16, 2007 Bumpy Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-370873 Share on other sites More sharing options...
cheechm Posted October 16, 2007 Author Share Posted October 16, 2007 Please guys Quote Link to comment https://forums.phpfreaks.com/topic/73025-calling-data-from-mysql/#findComment-370959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.