This is a simple problem but for some reason I am not seeing it. I am changing a piece of code from MySQL to MySQLi. The problem is that when I use the new MySQLi code, the select does not work.
I am showing three pieces of code. 1- The Index.php file including the codes 2. The Connect.php file showing how I connect to the DB 3. The Redirect.php class code using a function that is failing.
Inside the Redirect.php at the bottom, I have included the OLD code that works and the NEW code that does not work. All I see in the difference is that the new code is using the $con to communicate to the DB and I've tried global $con and it also fails. Please, I need your help. Can you let me know what I am doing wrong. Thanks.
<?php
/*******************************/
/* HERE IS THE INDEX.PHP FILE */
/*******************************/
session_start();
include("connection.php");
include("redirect.php");
$log=new redirect();
$log->check_logged();
$theme=$log->get_theme();
echo 'This is the Website Theme: ' . $theme . '<br>';
exit;
?>
<?php
/**************************************************/
/* HERE IS THE CONNECTION.PHP CODE BEING INCLUDED */
/**************************************************/
$con = mysqli_init( );
if (!$con)
{
die("ERROR: MySQLi Initialed failed");
}
if (!mysqli_real_connect($con, SERVERNAME,USERNAME,PASSWORD,DATABASENAME, NULL, NULL, MYSQL_CLIENT_INTERACTIVE))
{
die("MySQLi Real Connect Error: " . mysqli_connect_error());
}
?>
<?php
/**************************************************/
/* HERE IS THE REDIRECT.PHP CODE BEING INCLUDED */
/**************************************************/
class redirect
{
function __construct()
{ }
function check_logged()
{
if(isset($_SESSION['member_id']) && $_SESSION['member_id']!="")
{
if(isset($_GET['loginad']) && $_GET['loginad']==1)
header('location:'.SITEADDRESS_MEMBER.'memberoverview.php?loginad=1');
if(isset($_GET['surfad']) && $_GET['surfad']==1)
header('location:'.SITEADDRESS_MEMBER.'memberoverview.php?surfad=1');
else
header('location:'.SITEADDRESS_MEMBER.'memberoverview.php');
}
}
function get_theme()
{
/************************************************/
/* HERE IS THE OLD REDIRECT.PHP CODE THAT WORKS */
/************************************************/
$result = mysql_query("select * from theme where status='yes'");
if(mysql_num_rows($result)>0)
{
$data=mysql_fetch_array($result);
return $data['theme_name'];
}
/********************************************************************/
/* HERE IS THE NEW REDIRECT.PHP CODE BEING TESTED THAT DOESN'T WORK */
/********************************************************************/
$result = mysqli_query($con, "select * from theme where status='yes'")
if(mysqli_num_rows($result)>0)
{
$data=mysqli_fetch_array($result, MYSQLI_ASSOC);
return $data['theme_name'];
}
}
}
?>