santiagot16
04/01/2017, 19:47
buenas,
soy novato en esto de las páginas web, y he leído un poco.
ya tengo mi formulario en php y conectado a un servidor de prueba en el cual tiene mi base de datos, pero quiero ponerlo más interesante.
quiero que al ingresar un documento de identificación (Cédula) nuevo, este mire en la base de datos si la puedo utilizar, y si no, que me arroje un mensaje que me diga que esta cédula ya se encuentra en uso y que el registro no se lleve a cabo.
agradezco su ayuda.
PD: el programa que utilizo es Dreamweaver
El código lo dejo a continuación:
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']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO registro (Cedula, Nombres, Apellidos, Correo, `Empresa vinculada`, NIT, Contrasena, Tipo, Activo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Cedula'], "text"),
GetSQLValueString($_POST['Nombres'], "text"),
GetSQLValueString($_POST['Apellidos'], "text"),
GetSQLValueString($_POST['Correo'], "text"),
GetSQLValueString($_POST['Empresa_vinculada'], "text"),
GetSQLValueString($_POST['NIT'], "text"),
GetSQLValueString($_POST['Contrasena'], "text"),
GetSQLValueString($_POST['Tipo'], "text"),
GetSQLValueString($_POST['Activo'], "text"));
mysql_select_db($database_Proyecto, $Proyecto);
$Result1 = mysql_query($insertSQL, $Proyecto) or die(mysql_error());
$insertGoTo = "registro2.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
[/PHP]
soy novato en esto de las páginas web, y he leído un poco.
ya tengo mi formulario en php y conectado a un servidor de prueba en el cual tiene mi base de datos, pero quiero ponerlo más interesante.
quiero que al ingresar un documento de identificación (Cédula) nuevo, este mire en la base de datos si la puedo utilizar, y si no, que me arroje un mensaje que me diga que esta cédula ya se encuentra en uso y que el registro no se lleve a cabo.
agradezco su ayuda.
PD: el programa que utilizo es Dreamweaver
El código lo dejo a continuación:
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']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO registro (Cedula, Nombres, Apellidos, Correo, `Empresa vinculada`, NIT, Contrasena, Tipo, Activo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Cedula'], "text"),
GetSQLValueString($_POST['Nombres'], "text"),
GetSQLValueString($_POST['Apellidos'], "text"),
GetSQLValueString($_POST['Correo'], "text"),
GetSQLValueString($_POST['Empresa_vinculada'], "text"),
GetSQLValueString($_POST['NIT'], "text"),
GetSQLValueString($_POST['Contrasena'], "text"),
GetSQLValueString($_POST['Tipo'], "text"),
GetSQLValueString($_POST['Activo'], "text"));
mysql_select_db($database_Proyecto, $Proyecto);
$Result1 = mysql_query($insertSQL, $Proyecto) or die(mysql_error());
$insertGoTo = "registro2.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
Registro
[/PHP]