Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/06/2016, 12:06
mortisdj
 
Fecha de Ingreso: mayo-2014
Ubicación: Valencia
Mensajes: 63
Antigüedad: 10 años
Puntos: 0
Actualizar datos en la base de datos desde PHP

Buenas, a ver si me podéis indicar donde está mi problema que no doy con la solución, tengo el siguiente código para actualizar un registro, se muestra todo correctamente pero a la hora de darle al botón para guardar los cambios me dice "Query was empty" y no doy con la solución.

Os pego el código, gracias de antemano.

Código PHP:
<?php require_once('Connections/conexion.php'); ?>
<?php 
require_once('includes/funciones.php'); ?>
<?php 
if(isset( $_SESSION['MM_UserGroup']) &&  $_SESSION['MM_UserGroup']==1){?>
<?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;
}
}
$varcentro 0;
if (  isset(
$_GET['recordId']) && $_GET['recordId'] !=''){
$varcentro =    $_GET['recordId'];
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}


if ((isset(
$_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  
$insertSQL sprintf("UPDATE tbllibro SET strLibro=%s, strPrecio=%s, strAno=%s, strVentas=%s, strvVentas=%s, strDerechos=%s, strvDerechos=%s, strRetencion=%s, strValorRetencion=%s, strNeto=%s, intCliente=%s, strObserva=%s, strFecha=%s, intCliente=%s WHERE intLibro=%s",
                       
GetSQLValueString($_POST['strLibro'], "text"),
                       
GetSQLValueString($_POST['strPrecio'], "float"),
                       
GetSQLValueString($_POST['strAno'], "text"),
                       
GetSQLValueString($_POST['strVentas'], "int"),
                       
GetSQLValueString($_POST['strvVentas'], "float"),        
                       
GetSQLValueString($_POST['strDerechos'], "text"),
                       
GetSQLValueString($_POST['strvDerechos'], "float"),
                       
GetSQLValueString($_POST['strRetencion'], "int"),
               
GetSQLValueString($_POST['strValorRetencion'], "float"),
               
GetSQLValueString($_POST['strNeto'], "float"),               
               
GetSQLValueString($_POST['intCliente'], "intCliente"),                                           
               
GetSQLValueString($_POST['strObserva'], "text"),
                       
GetSQLValueString($_POST['strFecha'], "text"),
               
GetSQLValueString($_POST['intLibro'], "int"));
                       
  
mysql_select_db($database_conexion$conexion);
  
$Result1 mysql_query($insertSQL$conexion) or die(mysql_error());
  
  
$updateGoTo "clientes-list.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
    
$updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$updateGoTo));
}

$UsuarioId_ModificarDatos "0";
if (isset(
$_GET['recordId'])) {
  
$UsuarioId_DatosCentros2 $_GET['recordId'];
}

mysql_select_db($database_conexion$conexion);
$query_DatosCentros "SELECT * FROM tblclientes";
$DatosCentros mysql_query($query_DatosCentros$conexion) or die(mysql_error());
$row_DatosCentros mysql_fetch_assoc($DatosCentros);
$totalRows_DatosCentros mysql_num_rows($DatosCentros);

mysql_select_db($database_conexion$conexion);
$query_DatosCentros2 sprintf("SELECT * FROM tbllibro WHERE tbllibro.intLibro= %s"GetSQLValueString($varcentro"int"));
$DatosCentros2 mysql_query($query_DatosCentros2$conexion) or die(mysql_error());
$row_DatosCentros2 mysql_fetch_assoc($DatosCentros2);
$totalRows_DatosCentros2 mysql_num_rows($DatosCentros2);

?>
<!DOCTYPE html>
<html lang="es"><!-- InstanceBegin template="/Templates/Principal.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>miweb.es</title>
<meta name="description" content="">
<meta name="robots" content="index, follow">
<!-- InstanceEndEditable -->
<meta charset="utf-8">
<?php include("includes/precabecera.php"); ?>

<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>
<body>
<!-- InstanceBeginEditable name="EditRegion3" -->
<?php $menuseleccionado 6;?>
<section class="bg1">

  <header id="header">
    <div class="container_12">
      <?php include("includes/cabecera.php"); ?>
      <?php //include("includes/slider.php"); ?>
      <?php include("includes/menu.php"); ?>
    </div>
  </header>

 <div id="content">
    <div class="container_12">
        <div class="row">
 
            <div class="prefix_4 grid_6">
              <h3 class="mrg22 pad3">Añadir Nueva Factura al Autor</h3>        
             
    <form method="POST" action="<?php echo $editFormAction?>" name="form1">    
                    <br><br><h1>Autor:</h1>
                   <select name="intCliente" id="intCliente" class="seleccion">
                       <?php
do {  
?>
                       <option value="<?php echo $row_DatosCentros['intId']?><?php if (!(strcmp($varcentrohtmlentities($row_DatosCentros['intId'], ENT_COMPAT'utf-8')))) {echo "SELECTED";} ?>><?php echo  $row_DatosCentros['CliNombre']." - "$row_DatosCentros['CliApellidos']?></option>
                       <?php
} while ($row_DatosCentros mysql_fetch_assoc($DatosCentros));
  
$rows mysql_num_rows($DatosCentros);
  if(
$rows 0) {
      
mysql_data_seek($DatosCentros0);
      
$row_DatosCentros mysql_fetch_assoc($DatosCentros);
  }
?>
</select>
                     <label class="name">
                      <br><br><h1>Fecha:</h1>
                      <input type="text"  style="width:120px" name="strFecha"  class="seleccion" type="text" id="strFecha" type="file"  value="<?php echo htmlentities($row_DatosCentros2['strFecha'], ENT_COMPAT'utf-8'); ?>" />
                      
                   <div id="errorregistroespecialidad" class="ocultar texto-error">* Campo obligatorio</div>
                    </label>

                    <label class="name">
                      <br><br><h1>Libro: </h1>
                      
                      <select name="strLibro" id="select1" class="seleccion"  onchange="cargarSelect2(this.value)">
                    <option value="<?php echo htmlentities($row_DatosCentros2['strLibro'], ENT_COMPAT'utf-8'); ?>"><?php echo htmlentities($row_DatosCentros2['strLibro'], ENT_COMPAT'utf-8'); ?></option> 
<option value="Ref1">Ref1</option>
<option value="Ref2">Ref2</option>
<option value="Ref3">Ref3</option>
<option value="Ref4">Ref4</option>    
</select> 

 <div id="errorregistronombre" class="ocultar texto-error">* Campo obligatorio</div>                        
                    </label>
            </label>
            <label class="name">
                      <br><br><h1>Precio: </h1> 
                <select name="strPrecio" id="select2" class="seleccion"  onchange="seleccinado_select2();" disabled> 
                    <option value="<?php echo htmlentities($row_DatosCentros2['strPrecio'], ENT_COMPAT'utf-8'); ?>"><?php echo htmlentities($row_DatosCentros2['strPrecio'], ENT_COMPAT'utf-8'); ?></option> 
                </select> 
            </label>     
                      
[B]... EL RESTO DE CAMPOS[/B]
                    
                                     
                    <div>
                        <div class="clear"></div>
                        <div class="btns">
                           
                           <!-- <a id="botonalta" class="btn" href="javascript: document.form1.submit()" onClick="javascript: return validar();">Enviar</a>  -->
                             <input id="botonalta" class="botton" type="submit" value="Aceptar" onClick="javascript: return validar();"><br>
<br>

                   
                                           
                       
          </div>
                    </div>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="intLibro" value="<?php echo $row_DatosCentros2['intLibro']; ?>">
              </form>      
     
          </div>
        </div>
    </div>
  </div>

<?php include("includes/footer.php"); ?>
</section>
<!-- InstanceEndEditable -->
</body>
<!-- InstanceEnd -->

</html>
<?php
mysql_free_result
($DatosCentros);
mysql_free_result($DatosCentros2);
?>
<?php 
}else{ header("Location: index.php"); }/*restringir acceso a pagina*/?>