Hola, aqui tienes el codigo que diseñe tal como me lo pediste por el PM... estoy usando AJAX para guardar los datos en la BD... pruebalo y comentas
esto en tu tpl
clicks.tpl, entre el {if $clicks_ganador} y su correspondiente cierre {/if}:
Código:
{literal}
<script language="javascript" type="text/javascript">
function guardar_datos(nombre,email)
{
try {
xmlvar = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlvar = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlvar = false;
}
}
if (!xmlvar && typeof XMLHttpRequest!='undefined') {
xmlvar = new XMLHttpRequest();
}
_values_send="&nombre=" + nombre + "&email=" + email;
xmlvar_URL="reg.php?guardar";
xmlvar.open("POST",xmlvar_URL,true);
xmlvar.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlvar.send(_values_send);
xmlvar.onreadystatechange=function() {
if (xmlvar.readyState==4)
{
if(xmlvar.status==200)
{
alert(xmlvar.responseText);
location.replace('index.php');
}
}
}
}
alert('The pixel you selected is a winner pixel!! Please click OK to enter the contest!!\n Just fill the form with your Name and Email');
var nombre = prompt("Please write your name:","Your Name");
var email = prompt("Please write your email:","[email protected]");
guardar_datos(nombre,email);
</script>
{/literal}
Ahi esta el script en JS que te mostrara primero un alert diciendo que eres el ganador, luego te pedira nombre y email, y pasara estos datos a una pagina
reg.php en la que deberas colocar esto:
Código PHP:
<?php
if(isset($_GET['guardar'])) {
// AQUI GUARDAMOS LOS DATOS A LA BD
// PRIMERO DEBES REALIZAR LA CONEXION A LA BASE DE DATOS
@mysql_connect('SERVIDOR','USUARIO','CONTRASEÑA') or die('Error conectando a la bd');
@mysql_select_db('NOMBRE_DE_LA_BD') or die('Error seleccionando la bd');
$sql = "INSERT INTO mp_usrsorteo (nombre, email) VALUES
('".$_POST['nombre']."','".$_POST['email']."')";
if(mysql_query($sql)) {
// AQUI EL MENSAJE QUE SALDRA EN UN ALERT ANTES DE QUE SE REDIRECCIONE AL INDEX
echo 'Your data has been registered!! (Name:'.$_POST['nombre'].' - Email: '.$_POST['email'].')\n
Now you are in the contest.\nRemember that you can try all times you want!!';
} else {
echo 'No se insertaron los datos porque: '.mysql_error();
}
}
?>
me parece que asi esta bien
tanto codigo marea
Editado:
Añade {literal} y {/literal}
antes y despues del script respectiuvamente para que el sistema de templates Smarty, que es el que tu usas, reconozca el javascript