Ver Mensaje Individual
  #8 (permalink)  
Antiguo 18/01/2013, 10:08
davidscandroli
 
Fecha de Ingreso: noviembre-2012
Mensajes: 6
Antigüedad: 11 años, 5 meses
Puntos: 0
Respuesta: Verificar si existe antes de insertar.

Gracias yo lo pongo antes del insert pero como defino el campo strfecha si el mismo esta en el formulario? No entiendo eso.

Yo lo puse asi:

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}


$consulta="SELECT * FROM tblreservasespacios WHERE strFecha = ".$strFecha;
$resultado=mysql_query($consulta) or die (mysql_error());
if (mysql_num_rows($resultado)!=0)
{
echo("Exite al menos un registro");
} else {
echo("No Existen registros");
}



$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tblreservasespacios (strFecha, strUsuario, strDestino) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['strFecha'], "text"),
GetSQLValueString($_POST['strUsuario'], "text"),
GetSQLValueString($_POST['strDestino'], "int"));

mysql_select_db($database_conexion, $conexion);
$Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());

$insertGoTo = "reserva-espacios-comunes.ok.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>

Pero me tira este error:

Notice: Undefined variable: strFecha in D:\xampp\htdocs\torrecongreso\reserva-espacios-comunes.php on line 105