Foros del Web » Programando para Internet » PHP »

Problema PHP+Mysql

Estas en el tema de Problema PHP+Mysql en el foro de PHP en Foros del Web. Buenas a todos, estoy haciendo un código para modificar los registros de una tabla y me da un error, a ver si me podéis ayudar. ...
  #1 (permalink)  
Antiguo 15/03/2016, 12:36
 
Fecha de Ingreso: mayo-2014
Ubicación: Valencia
Mensajes: 63
Antigüedad: 9 años, 11 meses
Puntos: 0
Problema PHP+Mysql

Buenas a todos, estoy haciendo un código para modificar los registros de una tabla y me da un error, a ver si me podéis ayudar.

Por un lado tengo el código que me saca el listado de todos mis productos de la tabla, el cual funciona sin problemas.

Código PHP:
<?php require_once('Connections/conexion_libros.php'); ?>
<?php
$currentPage 
$_SERVER["PHP_SELF"];

function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

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

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO ps_order_history (id_order_history, id_employee, id_order, id_order_state, date_add) VALUES (%s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['id_order_history'], "int"),
                       
GetSQLValueString($_POST['id_employee'], "int"),
                       
GetSQLValueString($_POST['id_order'], "int"),
                       
GetSQLValueString($_POST['id_order_state'], "int"),
                       
GetSQLValueString($_POST['date_add'], "datetime"));

  
mysql_select_db($database_conexion_libros$conexion_libros);
  
$Result1 mysql_query($insertSQL$conexion_libros) or die(mysql_error());

  
$insertGoTo "ingreso_exitoso.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

$maxRows_consulta_libros 10;
$pageNum_consulta_libros 0;
if (isset(
$_GET['pageNum_consulta_libros'])) {
  
$pageNum_consulta_libros $_GET['pageNum_consulta_libros'];
}
$startRow_consulta_libros $pageNum_consulta_libros $maxRows_consulta_libros;

mysql_select_db($database_conexion_libros$conexion_libros);
$query_consulta_libros "SELECT * FROM ps_order_history";
$query_limit_consulta_libros sprintf("%s LIMIT %d, %d"$query_consulta_libros$startRow_consulta_libros$maxRows_consulta_libros);
$consulta_libros mysql_query($query_limit_consulta_libros$conexion_libros) or die(mysql_error());
$row_consulta_libros mysql_fetch_assoc($consulta_libros);

if (isset(
$_GET['totalRows_consulta_libros'])) {
  
$totalRows_consulta_libros $_GET['totalRows_consulta_libros'];
} else {
  
$all_consulta_libros mysql_query($query_consulta_libros);
  
$totalRows_consulta_libros mysql_num_rows($all_consulta_libros);
}
$totalPages_consulta_libros ceil($totalRows_consulta_libros/$maxRows_consulta_libros)-1;

$queryString_consulta_libros "";
if (!empty(
$_SERVER['QUERY_STRING'])) {
  
$params explode("&"$_SERVER['QUERY_STRING']);
  
$newParams = array();
  foreach (
$params as $param) {
    if (
stristr($param"pageNum_consulta_libros") == false && 
        
stristr($param"totalRows_consulta_libros") == false) {
      
array_push($newParams$param);
    }
  }
  if (
count($newParams) != 0) {
    
$queryString_consulta_libros "&" htmlentities(implode("&"$newParams));
  }
}
$queryString_consulta_libros sprintf("&totalRows_consulta_libros=%d%s"$totalRows_consulta_libros$queryString_consulta_libros);
?><!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=iso-8859-1" />
<title>Pedidos TuLibrodeFP</title>
</head>

<body>
<center><table border="1">
  <tr>
    <td><div align="center"><strong>Id History</strong></div></td>
    <td><div align="center"><strong>Empleado</strong></div></td>
    <td><div align="center"><strong>No de Pedido</strong></div></td>
    <td><div align="center"><strong>Estado</strong></div></td>
    <td><div align="center"><strong>Fecha</strong></div></td>
    <td colspan="2"><div align="center"><strong>Operaciones</strong></div></td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_consulta_libros['id_order_history']; ?></td>
      <td><?php echo $row_consulta_libros['id_employee']; ?></td>
      <td><?php echo $row_consulta_libros['id_order']; ?></td>
      <td><div align="center"><?php echo $row_consulta_libros['id_order_state']; ?></div></td>
      <td><div align="center"><?php echo $row_consulta_libros['date_add']; ?></div></td>
      <td><a href="modificar.php?Id_order_history=<?php echo $row_consulta_libros['id_order_history']; ?>">Modificar</a></td>
 </tr>
    <?php } while ($row_consulta_libros mysql_fetch_assoc($consulta_libros)); ?>
</table></center>
<p>
<table border="0" width="50%" align="center">
  <tr>
    <td width="23%" align="center"><?php if ($pageNum_consulta_libros 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_consulta_libros=%d%s"$currentPage0$queryString_consulta_libros); ?>">Primero</a>
          <?php // Show if not first page ?>
    </td>
    <td width="31%" align="center"><?php if ($pageNum_consulta_libros 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_consulta_libros=%d%s"$currentPagemax(0$pageNum_consulta_libros 1), $queryString_consulta_libros); ?>">Anterior</a>
          <?php // Show if not first page ?>
    </td>
    <td width="23%" align="center"><?php if ($pageNum_consulta_libros $totalPages_consulta_libros) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_consulta_libros=%d%s"$currentPagemin($totalPages_consulta_libros$pageNum_consulta_libros 1), $queryString_consulta_libros); ?>">Siguiente</a>
          <?php // Show if not last page ?>
    </td>
    <td width="23%" align="center"><?php if ($pageNum_consulta_libros $totalPages_consulta_libros) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_consulta_libros=%d%s"$currentPage$totalPages_consulta_libros$queryString_consulta_libros); ?>">&Uacute;ltimo</a>
          <?php // Show if not last page ?>
    </td>
  </tr>
</table>
</p>
</body>
</html>
<?php
mysql_free_result
($consulta_libros);
?>
Hasta aquí todo Ok, lista bien los productos.
  #2 (permalink)  
Antiguo 15/03/2016, 12:37
 
Fecha de Ingreso: mayo-2014
Ubicación: Valencia
Mensajes: 63
Antigüedad: 9 años, 11 meses
Puntos: 0
Respuesta: Problema PHP+Mysql

Cuando en el php anterior le doy a cualquier registro para modificarlo, en el php de modificar me da el siguiente error "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"

El códgigo del segundo script, es el siguiente:

Código PHP:
<?php require_once('Connections/conexion_libros.php'); ?>
<?php
function GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

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

if ((isset(
$_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  
$updateSQL sprintf("UPDATE ps_order_history SET id_employee=%s, id_order=%s, id_order_state=%s, date_add=%s WHERE id_order_history=%s",
                       
GetSQLValueString($_POST['id_employee'], "int"),
                       
GetSQLValueString($_POST['id_order'], "int"),
                       
GetSQLValueString($_POST['id_order_state'], "int"),
                       
GetSQLValueString($_POST['date_add'], "datetime"),
                       
GetSQLValueString($_POST['id_order_history'], "int"));

  
mysql_select_db($database_conexion_libros$conexion_libros);
  
$Result1 mysql_query($updateSQL$conexion_libros) or die(mysql_error());

  
$updateGoTo "modificar_exitoso.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
    
$updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$updateGoTo));
}

mysql_select_db($database_conexion_libros$conexion_libros);
$valor $_GET['id_order_history'];
$query_modificar_consulta "SELECT * FROM ps_order_history where id_order_history=$valor";
$modificar_consulta mysql_query($query_modificar_consulta$conexion_libros) or die(mysql_error());
$row_modificar_consulta mysql_fetch_assoc($modificar_consulta);
$totalRows_modificar_consulta mysql_num_rows($modificar_consulta);
?><!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=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<form method="post" name="form1" action="<?php echo $editFormAction?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Id History:</td>
      <td><?php echo $row_modificar_consulta['id_order_history']; ?></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Nombre:</td>
      <td><input type="text" name="id_employee" value="<?php echo $row_modificar_consulta['id_employee']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Autor:</td>
      <td><input type="text" name="id_order" value="<?php echo $row_modificar_consulta['id_order']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Cantidad:</td>
      <td><input type="text" name="id_order_state" value="<?php echo $row_modificar_consulta['id_order_state']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Precio:</td>
      <td><input type="text" name="date_add" value="<?php echo $row_modificar_consulta['date_add']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Actualizar registro"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="id_order_history" value="<?php echo $row_modificar_consulta['id_order_history']; ?>">
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result
($modificar_consulta);
?>
Y nada, que no doy con el error, a ver si alguien me puede echar un cable.

Mil gracias :)
  #3 (permalink)  
Antiguo 15/03/2016, 14:14
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: Problema PHP+Mysql

estas utilizando el codigo que viene por defecto en dreamweaver???? otra cosa si es php el tema debía estar en el sub foro de php.
__________________
[email protected]
HITCEL

Etiquetas: diseño-web, html, php-mysql, todo
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 16:40.