mvasco
mvasco

Reputation: 5101

MySQL table not found, but it exists

I am working on a web app with HTML5, PHP and MySQL. I have tested in on a local server with MAMP, and it is working fine.

Now I have uploaded all the files to a web server and exported the MySQL database. I have changed the data base connection file to implement the connection parameters to web mysql server.

I am testing the app on the web server and it is working fine, but on one file I am getting an error that doesn't happen on the local server. After calling a file, there appears an error message on the web browser:

enter image description here

I don't know why does it throw the error, then the table tb.Clientes does exist on the database, there are other pages that use that table and are not throwing the error.

How could I get the code line that is throwing the error?. I am not an expert PHP programmer.

UPDATED

It is too long, but I will include now some of my code:

<?php require_once('Connections/conexion.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);

  $logoutGoTo = "index.html";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "3,2,1";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "accesonoautorizado.html";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_Recordset1 = "-1";
if (isset($_GET['id'])) {
  $colname_Recordset1 = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_Recordset1 = sprintf("SELECT * FROM tbobras LEFT JOIN tbClientes ON tbobras.clienteObra = tbclientes.idCliente  WHERE idObra = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $conexion) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_presupmx = "-1";
if (isset($_GET['id'])) {
  $colname_presupmx = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_presupmx = sprintf("SELECT * FROM tbpresupuestosmx WHERE int_obra = %s AND tbpresupuestosmx.int_moneda =1", GetSQLValueString($colname_presupmx, "int"));
$presupmx = mysql_query($query_presupmx, $conexion) or die(mysql_error());
$row_presupmx = mysql_fetch_assoc($presupmx);
$totalRows_presupmx = mysql_num_rows($presupmx);

$colname_presudollar = "-1";
if (isset($_GET['id'])) {
  $colname_presudollar = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_presudollar = sprintf("SELECT * FROM tbpresupuestosmx WHERE int_obra = %s AND tbpresupuestosmx.int_moneda =2", GetSQLValueString($colname_presudollar, "int"));
$presudollar = mysql_query($query_presudollar, $conexion) or die(mysql_error());
$row_presudollar = mysql_fetch_assoc($presudollar);
$totalRows_presudollar = mysql_num_rows($presudollar);

$vardato_sumaingresos = "0";
if (isset($_GET['id'])) {
  $vardato_sumaingresos = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_sumaingresos = sprintf("SELECT SUM(tbingresos.estimacion) AS sumaestimacion, SUM(tbingresos.importeiva) AS sumaimporteiva, SUM(tbingresos.fondogarantia) AS sumafondogarantia , SUM(tbingresos.importefactura) AS  sumaimportefactura, SUM(tbingresos.totalcobrado) AS  sumatotalcobrado FROM tbingresos WHERE tbingresos.obra = %s AND tbingresos.moneda = 1", GetSQLValueString($vardato_sumaingresos, "int"));
$sumaingresos = mysql_query($query_sumaingresos, $conexion) or die(mysql_error());
$row_sumaingresos = mysql_fetch_assoc($sumaingresos);
$totalRows_sumaingresos = mysql_num_rows($sumaingresos);

$vardato_sumaingresos2 = "0";
if (isset($_GET['id'])) {
  $vardato_sumaingresos2 = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_sumaingresos2 = sprintf("SELECT SUM(tbingresos.estimacion) AS sumaestimacion, SUM(tbingresos.importeiva) AS sumaimporteiva, SUM(tbingresos.fondogarantia) AS sumafondogarantia , SUM(tbingresos.importefactura) AS  sumaimportefactura, SUM(tbingresos.totalcobrado) AS  sumatotalcobrado FROM tbingresos WHERE tbingresos.obra = %s AND tbingresos.moneda = 2", GetSQLValueString($vardato_sumaingresos2, "int"));
$sumaingresos2 = mysql_query($query_sumaingresos2, $conexion) or die(mysql_error());
$row_sumaingresos2 = mysql_fetch_assoc($sumaingresos2);
$totalRows_sumaingresos2 = mysql_num_rows($sumaingresos2);

$vardato_materialesgastosmxn = "1";
if (isset($_GET['id'])) {
  $vardato_materialesgastosmxn = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_materialesgastosmxn = sprintf("SELECT SUM(importe) as materiales FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=1 AND tbgastos.moneda=1", GetSQLValueString($vardato_materialesgastosmxn, "int"));
$materialesgastosmxn = mysql_query($query_materialesgastosmxn, $conexion) or die(mysql_error());
$row_materialesgastosmxn = mysql_fetch_assoc($materialesgastosmxn);
$totalRows_materialesgastosmxn = mysql_num_rows($materialesgastosmxn);

$vardato_manoobragastosmxn = "1";
if (isset($_GET['id'])) {
  $vardato_manoobragastosmxn = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_manoobragastosmxn = sprintf("SELECT SUM(importe) as manoobra FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=3 AND tbgastos.moneda=1", GetSQLValueString($vardato_manoobragastosmxn, "int"));
$manoobragastosmxn = mysql_query($query_manoobragastosmxn, $conexion) or die(mysql_error());
$row_manoobragastosmxn = mysql_fetch_assoc($manoobragastosmxn);
$totalRows_manoobragastosmxn = mysql_num_rows($manoobragastosmxn);

$vardato_herramientasgastosmxn = "1";
if (isset($_GET['id'])) {
  $vardato_herramientasgastosmxn = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_herramientasgastosmxn = sprintf("SELECT SUM(importe) as herramientas FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=5 AND tbgastos.moneda=1", GetSQLValueString($vardato_herramientasgastosmxn, "int"));
$herramientasgastosmxn = mysql_query($query_herramientasgastosmxn, $conexion) or die(mysql_error());
$row_herramientasgastosmxn = mysql_fetch_assoc($herramientasgastosmxn);
$totalRows_herramientasgastosmxn = mysql_num_rows($herramientasgastosmxn);

$vardato_equipogastosmx = "1";
if (isset($_GET['id'])) {
  $vardato_equipogastosmx = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_equipogastosmx = sprintf("SELECT SUM(importe) as equipo FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=6 AND tbgastos.moneda=1", GetSQLValueString($vardato_equipogastosmx, "int"));
$equipogastosmx = mysql_query($query_equipogastosmx, $conexion) or die(mysql_error());
$row_equipogastosmx = mysql_fetch_assoc($equipogastosmx);
$totalRows_equipogastosmx = mysql_num_rows($equipogastosmx);

$colname_Recordset2 = "-1";
if (isset($_GET['id'])) {
  $colname_Recordset2 = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_Recordset2 = sprintf("SELECT * FROM tbobras LEFT JOIN tbClientes ON tbobras.clienteObra = tbclientes.idCliente  WHERE idObra = %s", GetSQLValueString($colname_Recordset2, "int"));
$Recordset2 = mysql_query($query_Recordset2, $conexion) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);

$vardato_utilidadgastosmx = "1";
if (isset($_GET['id'])) {
  $vardato_utilidadgastosmx = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_utilidadgastosmx = sprintf("SELECT SUM(importe) as utilidad FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=7 AND tbgastos.moneda=1", GetSQLValueString($vardato_utilidadgastosmx, "int"));
$utilidadgastosmx = mysql_query($query_utilidadgastosmx, $conexion) or die(mysql_error());
$row_utilidadgastosmx = mysql_fetch_assoc($utilidadgastosmx);
$totalRows_utilidadgastosmx = mysql_num_rows($utilidadgastosmx);

$vardato_admingastosmx = "1";
if (isset($_GET['id'])) {
  $vardato_admingastosmx = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_admingastosmx = sprintf("SELECT SUM(importe) as administrativos FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=8 AND tbgastos.moneda=1", GetSQLValueString($vardato_admingastosmx, "int"));
$admingastosmx = mysql_query($query_admingastosmx, $conexion) or die(mysql_error());
$row_admingastosmx = mysql_fetch_assoc($admingastosmx);
$totalRows_admingastosmx = mysql_num_rows($admingastosmx);

$vardato_materialesgastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_materialesgastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_materialesgastosusd = sprintf("SELECT SUM(importe) as materiales FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=1 AND tbgastos.moneda=2", GetSQLValueString($vardato_materialesgastosusd, "int"));
$materialesgastosusd = mysql_query($query_materialesgastosusd, $conexion) or die(mysql_error());
$row_materialesgastosusd = mysql_fetch_assoc($materialesgastosusd);
$totalRows_materialesgastosusd = mysql_num_rows($materialesgastosusd);

$vardato_manobragastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_manobragastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_manobragastosusd = sprintf("SELECT SUM(importe) as manoobra FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=3 AND tbgastos.moneda=2", GetSQLValueString($vardato_manobragastosusd, "int"));
$manobragastosusd = mysql_query($query_manobragastosusd, $conexion) or die(mysql_error());
$row_manobragastosusd = mysql_fetch_assoc($manobragastosusd);
$totalRows_manobragastosusd = mysql_num_rows($manobragastosusd);

$vardato_herramientasgastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_herramientasgastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_herramientasgastosusd = sprintf("SELECT SUM(importe) as herramientas FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=5 AND tbgastos.moneda=2", GetSQLValueString($vardato_herramientasgastosusd, "int"));
$herramientasgastosusd = mysql_query($query_herramientasgastosusd, $conexion) or die(mysql_error());
$row_herramientasgastosusd = mysql_fetch_assoc($herramientasgastosusd);
$totalRows_herramientasgastosusd = mysql_num_rows($herramientasgastosusd);

$vardato_equipogastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_equipogastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_equipogastosusd = sprintf("SELECT SUM(importe) as equipo FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=6 AND tbgastos.moneda=2", GetSQLValueString($vardato_equipogastosusd, "int"));
$equipogastosusd = mysql_query($query_equipogastosusd, $conexion) or die(mysql_error());
$row_equipogastosusd = mysql_fetch_assoc($equipogastosusd);
$totalRows_equipogastosusd = mysql_num_rows($equipogastosusd);

$vardato_utilidadgastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_utilidadgastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_utilidadgastosusd = sprintf("SELECT SUM(importe) as utilidad FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=7 AND tbgastos.moneda=2", GetSQLValueString($vardato_utilidadgastosusd, "int"));
$utilidadgastosusd = mysql_query($query_utilidadgastosusd, $conexion) or die(mysql_error());
$row_utilidadgastosusd = mysql_fetch_assoc($utilidadgastosusd);
$totalRows_utilidadgastosusd = mysql_num_rows($utilidadgastosusd);

$vardato_admingastosusd = "1";
if (isset($_GET['id'])) {
  $vardato_admingastosusd = $_GET['id'];
}
mysql_select_db($database_conexion, $conexion);
$query_admingastosusd = sprintf("SELECT SUM(importe) as administrativos FROM tbgastos WHERE tbgastos.obra=%s  AND tbgastos.tipoGasto=8 AND tbgastos.moneda=2", GetSQLValueString($vardato_admingastosusd, "int"));
$admingastosusd = mysql_query($query_admingastosusd, $conexion) or die(mysql_error());
$row_admingastosusd = mysql_fetch_assoc($admingastosusd);
$totalRows_admingastosusd = mysql_num_rows($admingastosusd);
?>

Upvotes: 0

Views: 220

Answers (3)

iamsleepy
iamsleepy

Reputation: 540

The table name is pretty much case sensitive. From your code I saw that you did a join with the table tbClientes and tbclientes.

Eg:

"SELECT * FROM tbobras LEFT JOIN tbClientes ON tbobras.clienteObra = tbclientes.idCliente  WHERE idObra = %s", GetSQLValueString($colname_Recordset1, "int"));

Upvotes: 1

Ferrakkem Bhuiyan
Ferrakkem Bhuiyan

Reputation: 2783

1.Because MySQL uses directories and files to store databases and tables, database and table names are case sensitive if they are located on a file system that has case-sensitive file names.

2.Even for file systems that are not case sensitive, such as on Windows, all references to a given table within a query must use the same lettercase

Upvotes: 1

kayra
kayra

Reputation: 218

Step by step approach. Check for any include files Check connection parameters like server and username password. check table and database names

Upvotes: 1

Related Questions