Foros del Web » Programando para Internet » PHP »

Boton Submit toma valor NULL y no deja compararlo con su valor original

Estas en el tema de Boton Submit toma valor NULL y no deja compararlo con su valor original en el foro de PHP en Foros del Web. Hola amigos les cuento estoy haciendo un sistema de votacion de fotos las cuales las busco por nombre y al aparecer la foto q busco ...
  #1 (permalink)  
Antiguo 22/07/2010, 14:12
 
Fecha de Ingreso: diciembre-2007
Mensajes: 385
Antigüedad: 16 años, 4 meses
Puntos: 0
Boton Submit toma valor NULL y no deja compararlo con su valor original

Hola amigos les cuento estoy haciendo un sistema de votacion de fotos las cuales las busco por nombre y al aparecer la foto q busco abajito de la foto debe aparecer un boton con el nombre Votar he aqui mi problema y es q al hacer click en votar se me debe acumular ese voto para la foto pero el problema es q dicho boton Votar solo me toma el valor NULL lo q no me permite hacer la comparacion en el if para q me haga la actualizacion de votos y me sume el nuevo voto agregado, este es mi codigo:
Código PHP:
<!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>
<?php
$link 
mysql_connect('localhost''root''yo2bik');
if (!
$link)
   die(
'Error al conectarse con MySQL: ' mysql_error().' <br>Número del error: '.mysql_errno());
if (! @
mysql_select_db("pintatumundoagatha",$link)){
   echo 
"No se pudo conectar correctamente con la Base de datos";
   exit();
}
?>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>

   <br />
   <form id="busca_imagenes" name="busca_imagenes" method="post" action="">
   <fieldset>
  <table width="200" border="0" align="center">
      <tr>
        <td>Nombre Artista</td>
        <td><input type="text" name="nombre_artista" id="nombre_artista" /></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>Colegio</td>
        <td><label for="colegio_artista"></label>
          <input type="text" name="colegio_artista" id="colegio_artista" /></td>
        <td><input type="submit" name="Buscar" id="Buscar" value="Buscar" /></td>
      </tr>
      <tr>
        <td>Curso</td>
        <td><label for="curso_artista"></label>
          <input type="text" name="curso_artista" id="curso_artista" /></td>
        <td>&nbsp;</td>
      </tr>
  </table>
  </fieldset>


<?php

if ($_POST['Buscar'])
{
    
        if (
$_POST['nombre_artista'])
    {
        
$buscar_nombre_artista="select artista.*, pinturas.* from artista, pinturas where artista.id_artista=pinturas.id_artista and artista.nombre_artista='".$_POST['nombre_artista']."' and pinturas.id_artista=artista.id_artista";
        
        
$buscar_nombre_artista mysql_query($buscar_nombre_artista) or die(mysql_error());
                while(
$row=mysql_fetch_assoc($buscar_nombre_artista))
                {
                    echo 
"<form id='imagenes' name='imagenes' method='post' action=''>";
                    echo 
'<center><img src="'.$row['PINTURA_URL'].'"></img></center>';
                    echo 
'<center>Nombre: '.$row['NOMBRE_ARTISTA'].'</center>';
                    echo 
'<center>Curso: '.$row['CURSO_ARTISTA'].'</center>';
                    echo 
'<center>Colegio: '.$row['COLEGIO_ARTISTA'].'</center>';
                    
//echo "<center><input type='Submit' name='Algo' value='Algo' /></center>";
                    
?>
                   <center> <input type="submit" name="Votar" value="Votar"/></center>
                    <?php
                    print_r
($_POST["Votar"]);

                    echo 
"</form>";
                    
//var_dump($row);
                    
$_SESSION['id_pintura']=$row['ID_PINTURA'];
                }
                
                
$ide_pintura $_SESSION['id_pintura'];
                
                echo 
$consulta "SELECT voto FROM votacion WHERE id_pintura='".$ide_pintura."'"
    
$consulta mysql_query($consulta); 
    
$lado=mysql_num_rows($consulta);
    while(
$row_voto mysql_fetch_array($consulta)){ 
        
$votos$row_voto['voto'];
        echo 
$votos;
        
var_dump ($Votar);
                                
                                
    }

                
                 if((
$_POST['Votar'])=="Votar")
                {
                    
//header('Location: res.php');
                    
?>
<SCRIPT LANGUAGE="javascript">
       alert('Gracias por Votar');
                                                    
   </SCRIPT>
    <?php
                    
                    $votos 
$votos 1;
// actualizo la base de datos
    
echo $consulta "UPDATE votacion SET voto = '".$votos."' WHERE id_pintura='".$ide_pintura."'";
    
mysql_query($consulta,$link);

                }
        
    }
    
    
}
?>
</form>
</body>
</html>
en este if(($_POST['Votar'])=="Votar") debe entrar para actualizarme y sumarle el voto nuevo pero no se pq el boton Votar me toma el valor NULL por lo q no entra de ninguna forma a ese if ... como lo puedo hacer amigos para q me tome el valor q le doy y q no me tome el valor NULL???? porfavor agradeceria muchisimko su ayuda amigos!!!!
  #2 (permalink)  
Antiguo 22/07/2010, 14:27
 
Fecha de Ingreso: diciembre-2008
Mensajes: 190
Antigüedad: 15 años, 4 meses
Puntos: 6
Respuesta: Boton Submit toma valor NULL y no deja compararlo con su valor original

Buenas, esta bastante desprolijo el codigo:
1- El <form id="busca_imagenes" name="busca_imagenes" method="post" action="">
se debe cerrar antes de abrir el otro form.
2- El if(($_POST['Votar'])=="Votar") pueda estar por fuera del if ($_POST['Buscar'])
  #3 (permalink)  
Antiguo 22/07/2010, 14:31
 
Fecha de Ingreso: diciembre-2008
Mensajes: 190
Antigüedad: 15 años, 4 meses
Puntos: 6
Respuesta: Boton Submit toma valor NULL y no deja compararlo con su valor original

Con respeto, te modifique partes,porq me pareces q estas equivocado como pasas el id para aceptar el voto

Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <?php
  5. $link = mysql_connect('localhost', 'root', 'yo2bik');
  6. if (!$link)
  7.    die('Error al conectarse con MySQL: ' . mysql_error().' <br>Número del error: '.mysql_errno());
  8. if (! @mysql_select_db("pintatumundoagatha",$link)){
  9.    echo "No se pudo conectar correctamente con la Base de datos";
  10.    exit();
  11. }
  12. ?>
  13.  
  14. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  15. <title>Documento sin t&iacute;tulo</title>
  16. </head>
  17.  
  18. <body>
  19.  
  20.    <br />
  21.    <form id="busca_imagenes" name="busca_imagenes" method="post" action="">
  22.    <fieldset>
  23.   <table width="200" border="0" align="center">
  24.       <tr>
  25.         <td>Nombre Artista</td>
  26.         <td><input type="text" name="nombre_artista" id="nombre_artista" /></td>
  27.         <td>&nbsp;</td>
  28.       </tr>
  29.       <tr>
  30.         <td>Colegio</td>
  31.         <td><label for="colegio_artista"></label>
  32.           <input type="text" name="colegio_artista" id="colegio_artista" /></td>
  33.         <td><input type="submit" name="Buscar" id="Buscar" value="Buscar" /></td>
  34.       </tr>
  35.       <tr>
  36.         <td>Curso</td>
  37.         <td><label for="curso_artista"></label>
  38.           <input type="text" name="curso_artista" id="curso_artista" /></td>
  39.         <td>&nbsp;</td>
  40.       </tr>
  41.   </table>
  42.   </fieldset>
  43. </form>
  44.  
  45. <?php
  46.  
  47. if ($_POST['Buscar'])
  48. {
  49.      
  50.         if ($_POST['nombre_artista'])
  51.     {
  52.         $buscar_nombre_artista="select artista.*, pinturas.* from artista, pinturas where artista.id_artista=pinturas.id_artista and artista.nombre_artista='".$_POST['nombre_artista']."' and pinturas.id_artista=artista.id_artista";
  53.          
  54.         $buscar_nombre_artista = mysql_query($buscar_nombre_artista) or die(mysql_error());
  55.                 while($row=mysql_fetch_assoc($buscar_nombre_artista))
  56.                 {
  57.                     echo "<form id='imagenes' name='imagenes' method='post' action=''>";
  58.                     echo '<center><img src="'.$row['PINTURA_URL'].'"></img></center>';
  59.                     echo '<center>Nombre: '.$row['NOMBRE_ARTISTA'].'</center>';
  60.                     echo '<center>Curso: '.$row['CURSO_ARTISTA'].'</center>';
  61.                     echo '<center>Colegio: '.$row['COLEGIO_ARTISTA'].'</center>';
  62.                     //echo "<center><input type='Submit' name='Algo' value='Algo' /></center>";
  63.                     ?>
  64.                    
  65. <center> <input type="hidden" name="idpintura" value="<?php echo $row['ID_PINTURA'];?>"/></center>
  66. <center> <input type="submit" name="Votar" value="Votar"/></center>
  67.                     <?php
  68.                     echo "</form>";
  69.  
  70.                 }
  71.                                                
  72.     }
  73.  
  74.   }              
  75.                  if(($_POST['Votar'])=="Votar")
  76.                 {
  77.                     //header('Location: res.php');
  78.                     ?>
  79. <SCRIPT LANGUAGE="javascript">
  80.        alert('Gracias por Votar');
  81.                                                      
  82.    </SCRIPT>
  83.     <?php
  84.                      
  85.                     $votos = $votos + 1;
  86. // actualizo la base de datos
  87.  
  88.    $consulta = "UPDATE votacion SET voto = voto +1 WHERE id_pintura=".mysql_real_escape_string($_POST['idpintura']);  
  89.     mysql_query($consulta,$link);
  90.  
  91.                
  92.          
  93.     }
  94.      
  95.      
  96.  
  97. ?>
  98.  
  99. </body>
  100. </html>

Última edición por turfeano; 22/07/2010 a las 14:40
  #4 (permalink)  
Antiguo 22/07/2010, 17:03
 
Fecha de Ingreso: diciembre-2007
Mensajes: 385
Antigüedad: 16 años, 4 meses
Puntos: 0
Respuesta: Boton Submit toma valor NULL y no deja compararlo con su valor original

Hola turfeano, ahora si me entra al if pero ahora tambien no me toma la variable $_POST['idpintura'] la q utilizo para comparar el id d la pintura para aumentarle un voto .... como lo puedo hacer ahora??? porfa agradeceria mucho su ayuda amigos... de antemano gracias...

Etiquetas: null, original, submit, botones
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 04:51.