Gracias

| |||
![]() 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 |
| |||
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 |
| ||||
Re: Problema php-BD Encuesta ¿Algo así? Código PHP: |
| |||
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); ?> |