Xtremer360 Posted April 12, 2011 Share Posted April 12, 2011 Okay so I created a theme for my website that will also utilize a custom CMS script I developed and its not cooperating with me nicely. Here's my head of my header file for my template: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> <head> <title><?php bloginfo('name') ?>: <?php bloginfo('description') ?></title> <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" /> <meta http-equiv="content-type" content='<?php bloginfo("html_type"); ?> charset=<?php bloginfo('charset'); ?>' /> <?php if(is_singular()){ wp_enqueue_script('comment-reply');} ?> <?php wp_head(); ?> <?php require ('efedmanager/inc/dbconfig.php'); ?> </head> Now on my index page that calls the header file I DO NOT get a error saying that the file could not be located. So that's good news. Here's my dbconfig.php file. <?php /** * @author Jeff Davidson * @copyright 2010 */ // This file contains the database access information and establishes a connection to MySQL and selects the database // Set the database access information as contstants DEFINE ('DB_USER', '?'); DEFINE ('DB_PASSWORD', '?'); DEFINE ('DB_HOST', '?'); DEFINE ('DB_NAME', '?'); // Make the database connection $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (!$dbc) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } ?> Now when I go to one of my custom pages like this one it brings up the message: Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/xtremer/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()'d code on line 38 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/xtremer/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()'d code on line 39 <div id="champions" class="content"> <h1 class="pageheading">KOW Champions and Contenders</h1> <?php $championsQuery = " SELECT titles.titleName, titles.shortName, champions.champID, champions.con1ID, champions.con2ID, champions.con3ID, biochamp.shortName AS championshortName, biochamp.characterName AS champion, biocon1.shortName AS con1shortName, biocon1.characterName AS con1, biocon2.shortName AS con2shortName, biocon2.characterName AS con2, biocon3.shortName AS con3shortName, biocon3.characterName AS con3 FROM champions LEFT JOIN titles AS titles ON titles.ID = champions.titleID LEFT JOIN characters AS biochamp ON champions.champID = biochamp.ID LEFT JOIN characters AS biocon1 ON champions.con1ID = biocon1.ID LEFT JOIN characters AS biocon2 ON champions.con2ID = biocon2.ID LEFT JOIN characters AS biocon3 ON champions.con3ID = biocon3.ID WHERE titles.statusID = '1' ORDER BY titles.ID"; $championsResult = mysqli_query($dbc, $championsQuery); while ( $row = mysqli_fetch_array ( $championsResult, MYSQLI_ASSOC ) ) { $fieldarray=array('titleName','shortName','championID','championshortName','champion','con1ID','con1','con1shortName','con2ID','con2','con2shortName','con3ID','con3','con3shortName'); foreach ($fieldarray as $fieldlabel) { ${$fieldlabel} = $row[$fieldlabel]; } ?> <div id="title"><span class="large">< ?php echo $titleName ?></span> < ?php if (file_exists('images/championshots/'.$titleshortName.'/'.$championshortame.'.png')) { echo "<img class=champion src=images/championshots/".$shortName."/".$champion.".png alt= />\n"; } else { echo "<img class=champion src=images/championshots/".$shortName."/".$shortName.".png alt= />\n"; } if (strlen ($champion) < 1) { echo "<span class=medium>Vacant"; } else { echo "<span class=medium><a href=/bio?shortName=".$championshortName.">".$champion."</a></span>\n"; echo "<span class=medium>(Since TBD)</span>"; } ?> <span class="contender">Contenders</span> <ul> < ?php if ( strlen ($con1) < 1) { echo "<li><span class=medium>TBD</span>"; } else { echo "<li><a href=/bio?shortName=".$con1shortName.">".$con1."</a></li>\n"; } if (strlen ($con2) < 1) { echo "<li><span class=medium>TBD</span>"; } else { echo "<li><a href=/bio?shortName=".$con2shortName.">".$con2."</a></li>\n"; } if (strlen ($con3) < 1) { echo "<li><span class=medium>TBD</span>"; } else { echo "<li><a href=/bio?shortName=".$con3shortName.">".$con3."</a></li>\n"; } ?> </ul> </div> < ?php } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/ Share on other sites More sharing options...
dcro2 Posted April 12, 2011 Share Posted April 12, 2011 That would mean $dbc is null. This header file includes runtime.php? Quote Link to comment https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/#findComment-1200678 Share on other sites More sharing options...
Xtremer360 Posted April 12, 2011 Author Share Posted April 12, 2011 I understand that $dbc is null but not sure why. I know that the connection to the db through my dbconfig file is getting a good connection because its not giving me a message saying that the connection wasn't good. Quote Link to comment https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/#findComment-1200682 Share on other sites More sharing options...
Xtremer360 Posted April 12, 2011 Author Share Posted April 12, 2011 Any additional ideas? Quote Link to comment https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/#findComment-1200726 Share on other sites More sharing options...
mikosiko Posted April 12, 2011 Share Posted April 12, 2011 http://php.net/manual/en/language.variables.scope.php Dcro2 made you an important question related to that Quote Link to comment https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/#findComment-1200746 Share on other sites More sharing options...
Xtremer360 Posted April 12, 2011 Author Share Posted April 12, 2011 The dbconfig file is included in the header.php which is included in the page.php file as the header. So the $dbc variable is being accessed. Quote Link to comment https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/#findComment-1200748 Share on other sites More sharing options...
mikosiko Posted April 12, 2011 Share Posted April 12, 2011 the error that you are getting make reference to the file runtime.php you just only mentioned header.php/dbconfig and page.php Quote Link to comment https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/#findComment-1200775 Share on other sites More sharing options...
Xtremer360 Posted April 12, 2011 Author Share Posted April 12, 2011 It was a plugin I use for wordPress so that it will show my php coding inside my pages/posts Quote Link to comment https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/#findComment-1200777 Share on other sites More sharing options...
mikosiko Posted April 12, 2011 Share Posted April 12, 2011 without see your whole relevant code the only guess as I said... variable scope... and the final idea that I can offer is an old one... "debug your code"... echo is your very best friend a lot of times Quote Link to comment https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/#findComment-1200786 Share on other sites More sharing options...
Pikachu2000 Posted April 12, 2011 Share Posted April 12, 2011 Immediately before executing the query, var_dump($dbc); Quote Link to comment https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/#findComment-1200846 Share on other sites More sharing options...
Xtremer360 Posted April 13, 2011 Author Share Posted April 13, 2011 Okay i found out the issue is that my wordpress theme is having a hard time keeping a connection to my second database and didn't know if there's a good site I can go to that'll teach me some additional methods on how to include a second database connection that will grab information to use inside my wordpress pages. Quote Link to comment https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/#findComment-1201149 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.