Foros del Web » Programando para Internet » PHP »

Actualizar datos en la base de datos desde PHP

Estas en el tema de Actualizar datos en la base de datos desde PHP en el foro de PHP en Foros del Web. 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, ...
  #1 (permalink)  
Antiguo 24/06/2016, 12:06
 
Fecha de Ingreso: mayo-2014
Ubicación: Valencia
Mensajes: 63
Antigüedad: 9 años, 11 meses
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*/?>
  #2 (permalink)  
Antiguo 24/06/2016, 15:40
 
Fecha de Ingreso: julio-2010
Ubicación: La Ciudad Blanca, Mérida-Yucatán
Mensajes: 375
Antigüedad: 13 años, 9 meses
Puntos: 7
Respuesta: Actualizar datos en la base de datos desde PHP

Antes de ejecutar tu sentecia update, dale un echo y ve si te trae valores
__________________
--No todos aprendemos de la misma forma, ni a la misma velocidad---
  #3 (permalink)  
Antiguo 25/06/2016, 01:02
Avatar de xfxstudios  
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 10 meses
Puntos: 263
Respuesta: Actualizar datos en la base de datos desde PHP

no se porque utilizar a estas alturas los codigos de dreamweaver con tanta documentacion y tutoriales para esta tarea, de por si parte o todo tu codigo esta depreciado a nivel de la libreria mysql y pues, entre otras cosas
__________________
[email protected]
HITCEL
  #4 (permalink)  
Antiguo 25/06/2016, 12:46
 
Fecha de Ingreso: julio-2013
Mensajes: 309
Antigüedad: 10 años, 9 meses
Puntos: 2
Respuesta: Actualizar datos en la base de datos desde PHP

Muestra el código donde haces el update
  #5 (permalink)  
Antiguo 27/06/2016, 09:06
 
Fecha de Ingreso: mayo-2014
Ubicación: Valencia
Mensajes: 63
Antigüedad: 9 años, 11 meses
Puntos: 0
Respuesta: Actualizar datos en la base de datos desde PHP

Cita:
Iniciado por iniciopublic Ver Mensaje
Muestra el código donde haces el update
Código 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;
}
}
$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);

?>
  #6 (permalink)  
Antiguo 27/06/2016, 18:06
 
Fecha de Ingreso: mayo-2014
Ubicación: Valencia
Mensajes: 63
Antigüedad: 9 años, 11 meses
Puntos: 0
Respuesta: Actualizar datos en la base de datos desde PHP

Con eso el registro que he probado a editar es el 92 y haciendo un echo $insertSQL me devuelve lo siguiente:

UPDATE tbllibro SET strLibro='EIE', strPrecio=, strAno='2015/2016', strVentas=10, strvVentas=105.80, strDerechos='0.75', strvDerechos=0.79, strRetencion=19, strValorRetencion=0.1501, strNeto=0.6399, intCliente=9, strObserva='Prueba2', strFecha='12/12/2015' WHERE intLibro=92

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 ' strAno='2015/2016', strVentas=10, strvVentas=105.80, strDerechos='0.75', strvDe' at line 1

Veo que strPrecio me da un resultado sin nada :S

Última edición por mortisdj; 27/06/2016 a las 18:22
  #7 (permalink)  
Antiguo 27/06/2016, 18:26
 
Fecha de Ingreso: mayo-2014
Ubicación: Valencia
Mensajes: 63
Antigüedad: 9 años, 11 meses
Puntos: 0
Respuesta: Actualizar datos en la base de datos desde PHP

Y vale, solucionado, el problema estaba aquí...

<select name="strPrecio" id="select2" class="seleccion" onchange="seleccinado_select2();" disabled>

Ese disabled sobraba :S

Etiquetas: fecha, html, mysql, registro, select, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:34.