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

Tengo el siguiente formulario que debe verificar si existe en la base de datos esa fecha de existis no debe insertar el registro y de no existe si debe insertarlo.

Este es el formulario:

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Fecha:</td>
<td>
<input type="text" name="strFecha" id="datepicker" readonly="readonly" size="12" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td><input type="hidden" name="strUsuario" value="<?php echo $_SESSION['MM_Username'] ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">¿Que y cuando reservar?</td>
<td><select name="strDestino">
<option value="1" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>Parrilla Mediodia</option>
<option value="2" <?php if (!(strcmp(2, ""))) {echo "SELECTED";} ?>>Parrilla Noche</option>
<option value="3" <?php if (!(strcmp(3, ""))) {echo "SELECTED";} ?>>SUM de 08:00 a 13:30</option>
<option value="4" <?php if (!(strcmp(4, ""))) {echo "SELECTED";} ?>>SUM de 14:00 a 19:30</option>
<option value="5" <?php if (!(strcmp(5, ""))) {echo "SELECTED";} ?>>SUM de 20:00 a 06:00</option>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td><input type="submit" value="RESERVAR" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>


Este es el PHP del insert:

<?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;
}
}


$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));
}
?>

De ante mano, muchas gracias.