Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/233506-mysqli_query-returning-null/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.