Tema: Error en SQL
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/11/2014, 16:15
lux0o0
 
Fecha de Ingreso: diciembre-2012
Mensajes: 23
Antigüedad: 13 años, 9 meses
Puntos: 0
Error en SQL

Hola buenas, hice un login que redirecciona a diferentes paginas dependiendo del usuario , en todas esas paginas el usuario puede subir archivos a la base de datos y otra página para ver la lista de archivos en ella. Lo probé en localhost y no me da problemas, pero al subirla al servidor me lanza el siguiente error de sql
Código HTML:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
En el servidor me puedo loguear con el usuario y luego subir archivos, el error me aparece cuando ya subido el archivo y le doy al Enlace "Volver" (Que me dirige al index del usuario) me aparece ese error , lo mismo para cuando voy a la pagina de listar los archivos y quiero volver al index. No entiendo por que me lanza ese error en el servidor y no en localhost.

Les dejo los codigos de las 3 páginas involucradas, aunque yo creo que quizas el del problema es el index. pero ahí van.

index_mat.php

Código PHP:
<?php
if (!isset($_SESSION)) {
  
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** 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 == "") && true) { 
      
$isValid = true; 
    } 
  } 
  return 
$isValid; 
}

$MM_restrictGoTo = "../login_docente.php";
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;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<link href="../css/estilo.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php include("../includes/menu_docente.php");  ?>
</body>
</html>
guardar_archivo.php que se ejecuta luego de subir.php donde está el formulario para subir archivos.

Código PHP:
<head>
<link href="../css/estilo.css" rel="stylesheet" type="text/css" />
</head>
<div id="contenedor">
<?php 

$conn 
= mysql_connect("localhost","usuario","contraseña");   
mysql_select_db("basededatos");  
 

 
$archivo = $_FILES["archivito"]["tmp_name"]; 
 
$tamanio = $_FILES["archivito"]["size"];
 
$tipo    = $_FILES["archivito"]["type"];
 
$nombre  = $_FILES["archivito"]["name"];
 
$titulo  = $_POST["titulo"];
 if ( 
$archivo != "none" )
 {
    
$fp = fopen($archivo, "rb");
    
$contenido = fread($fp, $tamanio);
    
$contenido = addslashes($contenido);
    
fclose($fp); 

    
$qry = "INSERT INTO archivos_mat VALUES (0,'$nombre','$titulo','$contenido','$tipo')";
    
    
mysql_query($qry) or die("Error: ".mysql_error());
    
?> 


<?php
    
if(mysql_affected_rows($conn) > 0){
       print 
"Se ha guardado el archivo en la base de datos.</br>
       <a href='index_mat.php'>Volver</a>"
;
       
    }else
       print 
"NO se ha podido guardar el archivo en la base de datos.";
 }
 else
    print 
"No se ha podido subir el archivo al servidor"; 
 
?>
 
 </div>
listar_archivos.php

Código PHP:
<?php require_once('../Connections/uploadfiles.php'); ?>
<?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 ((isset(
$_GET['idElim'])) && ($_GET['idElim'] != "")) {
  
$deleteSQL = sprintf("DELETE FROM archivos_mat WHERE id=%s",
                       
GetSQLValueString($_GET['idElim'], "int"));

  
mysql_select_db($database_uploadfiles, $uploadfiles);
  
$Result1 = mysql_query($deleteSQL, $uploadfiles) or die(mysql_error());
}

mysql_select_db($database_uploadfiles, $uploadfiles);
$query_consulta_todo = "SELECT id, nombre, titulo, tipo FROM archivos_mat ORDER BY id ASC";
$consulta_todo = mysql_query($query_consulta_todo, $uploadfiles) or die(mysql_error());
$row_consulta_todo = mysql_fetch_assoc($consulta_todo);
$totalRows_consulta_todo = mysql_num_rows($consulta_todo);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<link href="../css/estilo.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
function verifica(){
    
    var ver = confirm('¿Desea Eliminar?');
    if(ver){
        return true;
        }else{
            return false;            
        }
    }

</script>
</head>

<body>
<div id="contenedor">
<a href="index_mat.php">Volver Atrás</a>
<table border="1" cellpadding="0" cellspacing="0" class="tb_archi" align="center">
  <tr>    
    <td>Nombre de archivo</td>
    <td>Descripción</td>
    <td>&nbsp;</td>    
  </tr>
  <?php do { ?>
    <tr>      
      <td><?php echo $row_consulta_todo['nombre']; ?></td>
      <td><?php echo $row_consulta_todo['titulo']; ?></td>
      <td><a onclick="return verifica()"href="listar_archivos_admin.php?idElim=<?php echo $row_consulta_todo['id']; ?>">Eliminar</a></td>      
    </tr>
    <?php } while ($row_consulta_todo = mysql_fetch_assoc($consulta_todo)); ?>
</table>
</div>
</body>
</html>
<?php
mysql_free_result
($consulta_todo);
?>
Les estaria muy agradecido si me pudieran ayudar