Foros del Web » Programando para Internet » PHP »

Ingreso un numero en mi formulario y me sale otro en la Base de Datos

Estas en el tema de Ingreso un numero en mi formulario y me sale otro en la Base de Datos en el foro de PHP en Foros del Web. Tengo este problema que me esta volviendo loco y no logro saber como arreglarlo: Tengo un formulario que tiene 3 campos... Id - que esta ...
  #1 (permalink)  
Antiguo 19/04/2008, 12:41
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Ingreso un numero en mi formulario y me sale otro en la Base de Datos

Tengo este problema que me esta volviendo loco y no logro saber como arreglarlo:


Tengo un formulario que tiene 3 campos...

Id - que esta oculto y es autoincrementable
Nombre - Varchar(50)
Telefono - varchar(10)

ingreso el nombre y me lo da bien en la DB
pero el numero que ponga en telefono
sea el que sea... me lo cambia y a todos me les pone el mismo valor

2147483647
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #2 (permalink)  
Antiguo 19/04/2008, 12:43
 
Fecha de Ingreso: agosto-2003
Mensajes: 324
Antigüedad: 20 años, 8 meses
Puntos: 1
Re: Ingreso un numero en mi formulario y me sale otro en la Base de Datos

¿Puedes poner código para mirarlo?
  #3 (permalink)  
Antiguo 19/04/2008, 12:58
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Ingreso un numero en mi formulario y me sale otro en la Base de Datos

Pongo todo completo para que lo analicen!

Código PHP:


<?php require_once('Connections/conexion.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_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO tabla (id, nombre, telefono) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST['id'], "int"),
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['telefono'], "int"));

  
mysql_select_db($database_conexion$conexion);
  
$Result1 mysql_query($insertSQL$conexion) or die(mysql_error());

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

mysql_select_db($database_conexion$conexion);
$query_cels "SELECT * FROM tabla ORDER BY id ASC";
$cels mysql_query($query_cels$conexion) or die(mysql_error());
$row_cels mysql_fetch_assoc($cels);
$totalRows_cels mysql_num_rows($cels);
?>


<?php    
    $link 
mysql_connect("localhost""elcapito_daecorp""seifer");
    
mysql_select_db("elcapito_celulares"$link);
    
    if (isset(
$_POST['eliminar_seleccion']))
        if (
count($_POST['seleccion']))
            foreach(
$_POST['seleccion'] as $id => $valor)
                
mysql_query("DELETE FROM tabla WHERE id = ".$id." LIMIT 1"$link);
?>


<!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>
<style type="text/css">
<!--
body,td,th {
    font-family: Segoe UI, Arial;
    font-size: 12px;
}
-->
</style></head>

<body>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="95%" border="0" cellpadding="5">
  <tr bgcolor="#CCCCCC">
    <td width="3%">ID</td>
    <td width="45%">Nombre</td>
    <td width="49%">Telefono</td>
    <td width="3%">&nbsp;</td>
  </tr>
<?php
    $result 
mysql_query("SELECT * FROM tabla"$link);
    while (
$row mysql_fetch_assoc($result)) {
?>
  <tr>
    <td><?php echo $row['id']; ?></td>
    <td><?php echo $row['nombre']; ?></td>
    <td><?php echo $row['telefono']; ?></td>
    <td><input type="checkbox" name="seleccion[<?php echo $row['id']; ?>]" /></td>
  </tr>
<?php
    
}
?>
</table>
<input name="eliminar_seleccion" type="submit" value="Eliminar Seleccion" />
</form> 


<p>&nbsp;</p>
<p>&nbsp;</p>

<form method="post" name="form1" action="<?php echo $editFormAction?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Nombre:</td>
      <td><input type="text" name="nombre" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Telefono:</td>
      <td><input type="text" name="telefono" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Insertar registro"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result
($cels);
?>
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México

Última edición por Capimaster; 19/04/2008 a las 12:59 Razón: Me falto un dato!
  #4 (permalink)  
Antiguo 19/04/2008, 13:07
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 7 meses
Puntos: 101
Re: Ingreso un numero en mi formulario y me sale otro en la Base de Datos

prueba cambiando esta linea:
GetSQLValueString($_POST['telefono'], "int"));
por
GetSQLValueString($_POST['telefono'], "text"));
Suerte
Salu2
__________________
Half Music - www.halfmusic.com
  #5 (permalink)  
Antiguo 19/04/2008, 13:41
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Ingreso un numero en mi formulario y me sale otro en la Base de Datos

Muchas gracias, eso resolvio mi problema...
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #6 (permalink)  
Antiguo 20/04/2008, 03:26
Avatar de DooBie  
Fecha de Ingreso: septiembre-2004
Mensajes: 1.101
Antigüedad: 19 años, 7 meses
Puntos: 71
Re: Ingreso un numero en mi formulario y me sale otro en la Base de Datos

Una pregunta Capimaster, por que el teléfono lo tienes como un campo varchar y no como un int o bigint, en teoría solo debe contener números, no?
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

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 22:11.