Foros del Web » Programando para Internet » PHP »

Problema php-BD Encuesta

Estas en el tema de Problema php-BD Encuesta en el foro de PHP en Foros del Web. Tengo una encuesta creada en php, el formulario lo envia correctamente, es mas he conseguido que la IP vaya a la base de datos, el ...
  #1 (permalink)  
Antiguo 14/01/2008, 13:02
 
Fecha de Ingreso: enero-2008
Ubicación: Valencia
Mensajes: 13
Antigüedad: 16 años, 3 meses
Puntos: 0
De acuerdo Problema php-BD Encuesta

Tengo una encuesta creada en php, el formulario lo envia correctamente, es mas he conseguido que la IP vaya a la base de datos, el problema me lo encuentro ahora, que quiero que cuando una IP esté ya en la base de datos no pueda volver a votar la misma IP, lo he intentado de mil maneras pero no consigo hacertarlo...la unica manera que lo he conseguido es haciendo que la columnas de IP sea única, pero el problema es que da un mensaje de error y queda bastante mal.... alguien me podria ayudar???

Gracias

Última edición por xiquet1975; 14/01/2008 a las 13:06 Razón: ampliar
  #2 (permalink)  
Antiguo 14/01/2008, 13:13
Avatar de hgp147  
Fecha de Ingreso: diciembre-2006
Ubicación: Buenos Aires, Argentina
Mensajes: 980
Antigüedad: 17 años, 3 meses
Puntos: 36
Re: Problema php-BD Encuesta

Hola xiquet1975;

Código PHP:
<?

$ip 
$_SERVER["REMOTE_ADDR"];

$result mysql_query("SELECT ip FROM encuesta WHERE ip='$ip'");

$row mysql_fetch_array($result);

if(empty(
$row)){

// Muestro formulario de encuesta

}else{

// Muestro resultado encuesta

}

?>
  #3 (permalink)  
Antiguo 15/01/2008, 03:56
 
Fecha de Ingreso: enero-2008
Ubicación: Valencia
Mensajes: 13
Antigüedad: 16 años, 3 meses
Puntos: 0
Re: Problema php-BD Encuesta

gracias ya lo tengo solucionado.. pero me gustaria saber una cosa mas... a ver si me la puedes solucionar... una vez que hace el voto y ha encontrado que la IP ya esta en la BD me gustaria que saliera un mensaje emergente en la misma pagina donde le pusiera "unicamente se puede votar una vez", se que que es algo como esto

MM_popupMsg('Unicamente se permite un voto por semana.')

pero no se exactamente donde deberia de colocarlos...

Un saludo y gracias

Última edición por xiquet1975; 15/01/2008 a las 03:58 Razón: aclarar
  #4 (permalink)  
Antiguo 15/01/2008, 13:44
Avatar de hgp147  
Fecha de Ingreso: diciembre-2006
Ubicación: Buenos Aires, Argentina
Mensajes: 980
Antigüedad: 17 años, 3 meses
Puntos: 36
Re: Problema php-BD Encuesta

¿Algo así?

Código PHP:
<?

$ip 
$_SERVER["REMOTE_ADDR"];

$result mysql_query("SELECT ip FROM encuesta WHERE ip='$ip'");

$row mysql_fetch_array($result);

if(empty(
$row)){

// Muestro formulario de encuesta

}else{

// Muestro resultado encuesta

echo "<script>alert('Unicamente se permite un voto por semana.');</script>";



}

?>
  #5 (permalink)  
Antiguo 16/01/2008, 12:20
 
Fecha de Ingreso: enero-2008
Ubicación: Valencia
Mensajes: 13
Antigüedad: 16 años, 3 meses
Puntos: 0
Re: Problema php-BD Encuesta

me he encontrado con un problema, y es que antes lo estaba probando todo en localhost, "apache" y todo funcionaba bien hasta ahora que lo he subido al servidor y me da problemas.
Uno de ellos es que cuando envio el formulario lo envia correctamente y los datos van correctamente a la BD, el problema que envio el voto no me envia a la pagina que le indico "plantilla.php", el otro problema es que me deja introducir varias IP iguales en la base de datos, y tambien le puse una variable para que si ya existia me enviara a otra pagina "plantilla2.php".. me podrias hechar un vistazo al codigo a ver que hago mal.. es que lo he intentado de mil maneras y no encuentro la solucion... Muchas gracias de antemano...

<?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")) {
$result = mysql_query("SELECT ip FROM encuesta WHERE ip='$ip'");
$row = mysql_fetch_array($result);

if(empty($row)){
$insertSQL = sprintf("INSERT INTO encuesta (ip, xxx, xxx, xxx, xxx,xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx, xxx) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['ip'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"),
GetSQLValueString($_POST['xxx'], "text"));

mysql_select_db($database_xxx, $xxx);
$Result1 = mysql_query($insertSQL, $xxx) or die(mysql_error());

$insertGoto = "plantilla.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoto .= (strpos($insertGoto, '?')) ? "&" : "?";
$insertGoto .= $_SERVER['QUERY_STRING'];
}

} else {
$insertGoto = "plantilla2.php";
}

header(sprintf("Location: %s", $insertGoto ));
}

$ip = $_SERVER["REMOTE_ADDR"];
mysql_select_db($database_xxx, $xxx);
$query_resultados = "SELECT COUNT( idencuestados) AS Countidencuestados FROM encuesta";
$resultados = mysql_query($query_resultados, $xxx) or die(mysql_error());
$row_resultados = mysql_fetch_assoc($resultados);
$totalRows_resultados = mysql_num_rows($resultados);
?>
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 18:10.