Ver Mensaje Individual
  #5 (permalink)  
Antiguo 16/01/2008, 12:20
xiquet1975
 
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);
?>