Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/01/2012, 12:24
wayward
(Desactivado)
 
Fecha de Ingreso: enero-2004
Mensajes: 136
Antigüedad: 20 años, 3 meses
Puntos: 0
problema con formulario

Hola a todos.

Estoy desarrollando un backoffice para una web, y he creado diferentes formularios para añadir registros o modificarlos en la bd. Todo funcio correctamente, sin embargo creo que los datos que pasan por el $_GET y el $_POST me estan haciendo una mala pasada, pq de vez en cuando, cuando modifico algun registro se me modifica alguno diferente al que yo quiero.

El codigo es bastante extenso, así que he realizado una version mini light para que veaios de que se trata.

En la parte superior hay un buscador que localiza el registro, y un poco mas abajo algunos campos para modificar. Como he dicho se modifica sin problea, pero noto siempre que voy a dar al voton de actualizar, que todavia estan presentes los datos utilizados para la busqueda.

Espero que me podais ayudar.

Un saludo.

<?php require_once('Connections/aluxbd.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;
}
}

$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 ads SET NOMBRE=%s, EDAD=%s WHERE ID_PUBLICIDAD=%s",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['edad'], "text"),
GetSQLValueString($_POST['id'], "int"));

mysql_select_db($database_aluxbd, $aluxbd);
$Result1 = mysql_query($updateSQL, $aluxbd) or die(mysql_error());
}

$colname_Recordset1 = "-1";
if (isset($_GET['id-busqueda'])) {
$colname_Recordset1 = $_GET['id-busqueda'];
}
mysql_select_db($database_aluxbd, $aluxbd);
$query_Recordset1 = sprintf("SELECT ID_PUBLICIDAD, NOMBRE, EDAD FROM ads WHERE ID_PUBLICIDAD = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $aluxbd) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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>Untitled Document</title>
</head>

<body>
<table width="1000" cellpadding="0" cellspacing="2" border="0">
<form id="busqueda" action="" method="get" enctype="multipart/form-data">
<tr>
<td colspan="4" id="busqueda1" >&nbsp;</td>
</tr>
<td colspan="4" id="busqueda1" style="style" align="center" >BUSCA EL ANUNCIO QUE DESEAS LOCALIZAR</td>
<tr>
<td></tr></td>
</tr>
<tr>
<td width="308">&nbsp;</td>
<td width="178">&nbsp;</td>
<td width="192">&nbsp;</td>
<td width="294">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td id="busqueda2" >ID ANUNCIO</td>
<td ><label for="id-busqueda"></label>
<input type="text" name="id-busqueda" id="id-busqueda" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td id="busqueda2">TELEFONO</td>
<td><label for="telf-busqueda"></label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="4" style="style" align="center"><input type="submit" name="buscar" id="buscar" value="Buscar" action="<?php $_SERVER['PHP_SELF'];?>"/></td>
</tr>
</form>
</table>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<label for="id"></label>
<input name="id" type="text" id="id" value="<?php echo $row_Recordset1['ID_PUBLICIDAD']; ?>" />
<label for="name"></label>
<input name="name" type="text" id="name" value="<?php echo $row_Recordset1['NOMBRE']; ?>" />
<label for="edad"></label>
<input name="edad" type="text" id="edad" value="<?php echo $row_Recordset1['EDAD']; ?>" />
<input type="hidden" name="MM_update" value="form1" />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

<p></p>
</body>
</html>