Código PHP:
<?php require_once('Connections/test.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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']);
}
$var1_Recordset1 = "none";
if (isset($_POST['lu'])) {
$var1_Recordset1 = $_POST['lu'];
}
$var2_Recordset1 = "none";
if (isset($_POST['ma'])) {
$var2_Recordset1 = $_POST['ma'];
}
$var3_Recordset1 = "none";
if (isset($_POST['mi'])) {
$var3_Recordset1 = $_POST['mi'];
}
$var4_Recordset1 = "none";
if (isset($_POST['ju'])) {
$var4_Recordset1 = $_POST['ju'];
}
$var5_Recordset1 = "none";
if (isset($_POST['vi'])) {
$var5_Recordset1 = $_POST['vi'];
}
$var6_Recordset1 = "none";
if (isset($_POST['sa'])) {
$var6_Recordset1 = $_POST['sa'];
}
mysql_select_db($database_test, $test);
$query_Recordset1 = sprintf("SELECT apeido, nombre, lu, ma, mi, ju, vi, sa, salon FROM nombre WHERE lu = %s AND ma=%s AND mi=%s AND ju=%s AND vi=%s AND sa=%s", GetSQLValueString($var1_Recordset1, "text"),GetSQLValueString($var2_Recordset1, "text"),GetSQLValueString($var3_Recordset1, "text"),GetSQLValueString($var4_Recordset1, "text"),GetSQLValueString($var5_Recordset1, "text"),GetSQLValueString($var6_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $test) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
//////////////////////// AQUI ESTOY VALIDANDO Y CREO UNA VARIABLE QUE SIRVE PARA EL MENSAJE///////////////////////////
$yaRegistrado = false;
if ($totalRows_Recordset1 > 0) {
$yaRegistrado = true;
}
else {
///////////////////////////////////////////////////////////////////////////////////
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO nombre (apeido, nombre, lu, ma, mi, ju, vi, sa, salon) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['apeido'], "text"),
GetSQLValueString($_POST['nombre'], "text"),
GetSQLValueString($_POST['lu'], "text"),
GetSQLValueString($_POST['ma'], "text"),
GetSQLValueString($_POST['mi'], "text"),
GetSQLValueString($_POST['ju'], "text"),
GetSQLValueString($_POST['vi'], "text"),
GetSQLValueString($_POST['sa'], "text"),
GetSQLValueString($_POST['salon'], "text"));
mysql_select_db($database_test, $test);
$Result1 = mysql_query($insertSQL, $test) or die(mysql_error());
$insertGoTo = "p1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.advertencia {
font-family: "Comic Sans MS", cursive;
font-weight: bold;
color: #F00;
}
-->
</style>
</head>
<body><?php if ($_POST && $yaRegistrado) {
echo '<p class="advertencia">'.$_POST['lu'].''.$_POST['ma'].''.$_POST['mi'].''.$_POST['ju'].''.$_POST['vi'].''.$_POST['sa'].' Existe un empalme de materias</p>';
}
?>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<label>nombre
<br />
<input type="text" name="nombre" id="nombre" />
<br />
</label>
<label>apeido<br />
<input type="text" name="apeido" id="apeido" />
<br />
</label>
<label>lu
<br />
<input type="text" name="lu" id="lu" />
<br />
</label>
<label>ma
<br />
<input type="text" name="ma" id="ma" />
<br />
</label>
<label>mi
<br />
<input type="text" name="mi" id="mi" />
<br />
</label>
<label>ju
<br />
<input type="text" name="ju" id="ju" />
<br />
</label>
<label>vi
<br />
<input type="text" name="vi" id="vi" />
<br />
</label>
<label>sa
<br />
<input type="text" name="sa" id="sa" />
<br />
</label>
salon
<label>
<br />
<input type="text" name="salon" id="salon" />
<br />
</label>
<label>
<input type="submit" name="button" id="button" value="Submit" />
</label>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>