Foros del Web » Programando para Internet » PHP »

Vote on click

Estas en el tema de Vote on click en el foro de PHP en Foros del Web. ESTE ES MI CODIGO, LA IDEA ES QUE AL HACER CLICK EN UNA IMAGEN SE LE SUME UN PUNTO EN LA BASE DE DATOS AL ...
  #1 (permalink)  
Antiguo 09/05/2012, 13:51
 
Fecha de Ingreso: enero-2012
Ubicación: Buenos Aires
Mensajes: 13
Antigüedad: 12 años, 3 meses
Puntos: 0
De acuerdo Necesito ayuda!

ESTE ES MI CODIGO, LA IDEA ES QUE AL HACER CLICK EN UNA IMAGEN SE LE SUME UN PUNTO EN LA BASE DE DATOS AL CAMPO VOTOS QUE TENGA COMO ID EL ID DE LA IMAGEN! PERO AL HACER CLICK EN LA IMAGEN NO SUCEDE NADA, PODRIAN CORREGIRME EL CODIGO POR FAVOR?? DESDE YA MUCHAS GRACIAS

Código PHP:
<center>
<p><strong>Are looks supposed to matter?No. Will we be judged by them? Yes.
<p><strong>Who's hotter? Click to choose</strong></p>
<table align="center" width="410" border="0" cellspacing="5" cellpadding="5" height="250" cellspacing="0" cellpadding="0">
<tr><td width="200">

<?php
$datos
=mysql_query("select * from fotos where id='$id1'");
if(
$foto1=mysql_fetch_array($datos)){


echo 
"<form method='post' action='' name='form1'><input type='image' name='foto1' src='fotos/".$foto1[nombre].".".$foto1[formato]."' width='200' height='250' onsubmit=$votar></form>";
function 
votar($votar){
$votar=mysql_query("update fotos set votos='$foto1[votos]'+1 where id='$id1'");
}
}
?>
















</td>

<td width="10">Or</td>

<td width="200">


<?php
$datos2
=mysql_query("select * from fotos where id='$id2'");
if(
$foto2=mysql_fetch_array($datos2)){



echo 
"<form method='post'  action='' name=form2><input onsubmit=$votar2 name='foto2' type='image' src='fotos/".$foto2[nombre].".".$foto2[formato]."' width='200' height='250'></form>";


}
?>



</td></tr></table>

</center>
<hr id="menu_bottom">
<table align="center" border="0" width="100%">

<tr><td align="right" width="50%"><a style="margin:50px;" href=top10.php>Top 10 </a></td><td align="left"><a style="margin:50px;" href="submit.php"> Submit Video </a>

Última edición por ezebongiovi; 09/05/2012 a las 15:54
  #2 (permalink)  
Antiguo 10/05/2012, 12:19
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 11 meses
Puntos: 127
Respuesta: Vote on click

humm.. al parecer no comprendes mucho las funciones de un form, el desarrollo web,y el desarrollo de aplicaciones cliente servidor.

pequeña clase para primerizos.

1 un form es para enviar firmularios osea datos.(hay que colocar el id de la foto en un input escondido para enviar el id de la foto al pinchar sobre ella)
2 el submint es automatico cuando haces y input type=image .
3 php se ejecuta en el servidor, devolviendo codigo html al navegador para interpretarlo.
osea se puede evaluar el id dela foto cada ves que entre, y si hay id sumar el voto
4 por ultimo si usas dreamweaver (sino porfavor usalo) escapa todo el HTML que puedas del codigo php.
EJEMPLO:
Código PHP:
// En lugar de hacer
echo='<input name="id" value="'.$foto1[id].'" type="text">';

//Es mejor
?><input name="id" value="1<?=$foto1[id]?>" type="text"><?
//si haces esto el DW mostrara el input en la pestaña diseño y no te pierdes tanto, ademas de que el procesoen el servidor gana y nos cuantos nanosegundos

fuentes:
http://webdesign.about.com/od/htmlta...-image-tag.htm
http://soporte.miarroba.es/17452/281...-de-una-celda/

TU SOLUCION:

Código PHP:
<?php
$id
=trim($_POST[id]);
if(
$id!=""){
mysql_query("update fotos set votos=votos+1 where id='$id'");
}
?>
<center>
<p><strong>Are looks supposed to matter?No. Will we be judged by them? Yes.</strong>
<p><strong>Who's hotter? Click to choose</strong></p>
<table align="center" width="410" border="0" height="250" cellspacing="0" cellpadding="0">
<tr><td width="200">
<?php
$datos
=mysql_query("select * from fotos where id='$id1'");
if(
$foto1=mysql_fetch_array($datos)){
?>
<form method='post' action='' name='form1'>
<input name="id" value="1<?=$foto1[id]?>" type="hidden">
<input type='image' src='fotos/<?=$foto1[nombre].".".$foto1[formato]?>' width='200' height='250'>
</form>
<?php
}
?>
</td>
<td width="10">Or</td>
<td width="200">
<?php
$datos2
=mysql_query("select * from fotos where id='$id2'");
if(
$foto2=mysql_fetch_array($datos2)){
?>
<form method='post'  action='' name='form2'>
<input name="id" value="2<?=$foto2[id]?>" type="hidden">
<input  type='image' src='fotos/<?=$foto2[nombre].".".$foto2[formato]?>' width='200' height='250'></form>
<?php
}
?>
</td></tr></table>

</center>
<hr id="menu_bottom">
<table align="center" border="0" width="100%">

<tr><td align="right" width="50%"><a style="margin:50px;" href=top10.php>Top 10 </a></td><td align="left"><a style="margin:50px;" href="submit.php"> Submit Video </a></td></tr></table>

revisalo y analizalo

Etiquetas: sql, vote
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 08:30.