Foros del Web » Programando para Internet » PHP »

update en php no funciona al tener letras

Estas en el tema de update en php no funciona al tener letras en el foro de PHP en Foros del Web. tengo el siguiente php Código PHP: <?php        include_once  "conexion.php" ;       header ( "Content-Type: text/html;charset=utf-8" ); ?> <!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>PANEL</title> <style>     body {      margin:0;  ...
  #1 (permalink)  
Antiguo 19/11/2012, 10:33
 
Fecha de Ingreso: enero-2004
Mensajes: 72
Antigüedad: 20 años, 3 meses
Puntos: 1
update en php no funciona al tener letras

tengo el siguiente php

Código PHP:
<?php 
     
include_once "conexion.php";
     
header("Content-Type: text/html;charset=utf-8");
?>
<!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>PANEL</title>
<style> 
   body { 
    margin:0; 
    padding:0; 
    text-align:center; 
   } 

   #content {
    text-align: left;
    margin: auto;
    background-color: #FFF;
    width: 1100px;
    height: 700px;
   } 

   #cabecera {
    width: 1100px;
    height: 200px;
    background-color: #FFF;
   } 

   #menu {
    width: 150px;
    height: 400px;
    float: left;
    background-color: #FFF;
   } 

   #contenido {
    width: 800px;
    height: 400px;
    float: left;
    background-color: #FFF;
   } 

   #pie {
    clear: both;
    width: 1100px;
    height: 50px;
    background-color: #FFF;
   } 

</style> 
<script languaje="javascript">
function validar(){
    if(form1.cod.value==''){
        alert('ingrese un codigo valido');
        form1.cod.focus();
        return false;
    }
    if(form1.rut.value==''){
        alert('ingrese un rut');
        form1.rut.focus();
        return false;
}
}
</script>
<script>
function validarNro(e) {
var key;
if(window.event) // IE
    {
    key = e.keyCode;
    }
else if(e.which) // Netscape/Firefox/Opera
    {
    key = e.which;
    }

if (key < 48 || key > 57)
    {
    if(key == 46 || key == 8) // Detectar . (punto) y backspace (retroceso)
        { return true; }
    else 
        { return false; }
    }
return true;
}
</script>
<script>
function validarNro(e) {
var key;
if(window.event) // IE
    {
    key = e.keyCode;
    }
else if(e.which) // Netscape/Firefox/Opera
    {
    key = e.which;
    }

if (key < 48 || key > 57)
    {
    if(key == 46 || key == 8) // Detectar . (punto) y backspace (retroceso)
        { return true; }
    else 
        { return false; }
    }
return true;
}
</script>
<style type="text/css">
.ads {
    font-weight: bold;
    font-family: Arial;
}
.dc {
    font-family: Arial;
    font-weight: normal;
}
.dc1 {
    font-family: Arial;
}
</style>
</head>
<body>
<div id="content"> 
  <div id="cabecera"><img src="portada1.jpg" alt="" width="1100" height="200" align="top" /></div> 
  <div id="menu"></div> 
  <div id="contenido">
    <div align="center">
<form method="post" id="form1" name="form1" form action="" class="login" onsubmit="return validar();"/>
<table width="799" border="0">
  <tr>
      <td colspan="3" align="center"><p><strong><span class="dc1">INGRESE LOS DATOS SOLICITADOS</span></strong></p>
      <p><?php 
if(isset($_POST['enviar']))
{
    if(
$_POST['cod'] == '')
    {
        echo 
'Por favor llene todos los campos.';
    }
    else
    {
        
$sql 'SELECT * FROM codigo';
        
$rec mysql_query($sql);
        
$verificar_cod 0;
 
        while(
$result mysql_fetch_object($rec))
        {
            if(
$result->codt == $_POST['cod'])
            {
                
$verificar_cod 1;
            }
        }
 
        if(
$verificar_cod == 1)
        {
            if(
$_POST['cod'] == $_POST['cod'])
            {
                
$cod $_POST['cod'];
                
$estado $_POST['estado'];
                
$sql "UPDATE codigo SET estado='$estado' WHERE codt=$cod";
                
mysql_query($sql);
                echo 
'cambio codigo correctamente.';
            }
            else
            {
                echo 
'';
            }
        }
        else
        {
            echo 
'no existe';
            
        }
    }
}
?>
    </p></td>
  </tr>
    <tr>
      <td width="341" align="right"><p><strong><span class="dc">Codigo</span>:</strong></p></td>
      <td width="448" colspan="2" align="left"><p>
        <input name="cod" type="text" value="" maxlength="5" />
      </p></td>
    </tr>
    <tr>
      <td align="right" class="ads"><span class="dc">Estado</span> </td>
      <td colspan="2" align="left"><label>
        <input name="estado" type="radio" id="RadioGroup1_0" value="activo" checked="checked" />
        <span class="dc">Activo</span></label>
        <br />
        <label>
          <input type="radio" name="estado" value="inactivo" id="RadioGroup1_1" />
      <span class="dc">Inactivo</span></label></td>
    </tr>
    <tr>
      <td colspan="3" align="center"><input type="submit" name="enviar" value="Registrar" /></td>
    </tr>
    <tr>
      <td colspan="3" align="center"><p class="login">
        <input type="button" value="Volver " onclick="location.href = 'reg_codigo.php'" />
      </p>
        <p class="login">&nbsp;</p>
    
   
  <img src="divisor1.png" width="799" height="10" alt="" /> 
    </tr>
</table>
<table width="799" border="0">
  <tr>
      <td align="center" valign="top"><?php 
$result 
mysql_query("SELECT codt, ref1, ref2, estado FROM codigo");
if (
$row mysql_fetch_array($result)){ 
   echo 
"<table border = '1'> \n"
   echo 
"<tr><td>CODIGO</td><td>REFERENCIA </td><td>REFERENCIA2 </td><td>estado </td></tr> \n"
   do { 
      echo 
"<tr><td>".$row["codt"]."</td><td>".$row["ref1"]."</td><td>".$row["ref2"]."</td><td>".$row["estado"]."</td></tr> \n"
   } while (
$row mysql_fetch_array($result)); 
   echo 
"</table> \n"
} else { 
echo 
"¡ No se ha encontrado ningún registro !"

?></td>
    </tr>
</table>
'
  
   </div>
  </div>
 <script language="Javascript">
document.oncontextmenu = function(){return false};
</script>    
</body>
</html>
el tema es que al tratar de cambiar el estado de un codigo con letras no me cambia, pero si los que son solo numeros

en la bd esta todo varchar(10)
donde estar a el problema... ¿¿?¿??

muchas gracias por su tiempo
  #2 (permalink)  
Antiguo 22/11/2012, 06:03
 
Fecha de Ingreso: enero-2004
Mensajes: 72
Antigüedad: 20 años, 3 meses
Puntos: 1
Respuesta: update en php no funciona al tener letras

no hay caso .. no eh podido si alguien s ele ocurre algo .. se lo agradesco
  #3 (permalink)  
Antiguo 22/11/2012, 06:50
Avatar de Trublux  
Fecha de Ingreso: octubre-2010
Ubicación: Madrid
Mensajes: 355
Antigüedad: 13 años, 6 meses
Puntos: 48
Respuesta: update en php no funciona al tener letras

No sé si sera esto pero:
Código MySQL:
Ver original
  1. UPDATE codigo SET estado='$estado' WHERE codt=$cod
Estaría mejor así:
Código MySQL:
Ver original
  1. UPDATE codigo SET estado='$estado' WHERE codt='$cod';
__________________
eZ Publish Developer Basic Legacy
eZ Publish Developer Basics (4.4)
Alojamientos rurales en España

Etiquetas: html, letras, mysql, registro, sql, tener, update
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 11:03.