PHP - Alguien podría ayudarme con este script para guardar la Cedula en la base de datos?

 
Vista:

Alguien podría ayudarme con este script para guardar la Cedula en la base de datos?

Publicado por XXX (7 intervenciones) el 05/11/2006 00:24:16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<html>
<body>
<?php
if (isset($_POST["enviar"]))
{
$link = mysql_connect("localhost", "root","123");
mysql_select_db("america2",$link);
$res = mysql_query("SELECT cedula, nombres, apellidos  FROM datos_personales WHERE cedula == ($cedula)");
$res = mysql_query($sql);
if ($res = true) then
{
printf (Ya existe alguien con este numero de cedula.\n);
}
else
{
$sql = "INSERT INTO datos_personales (cedula, nombres, apellidos) VALUES ('".$_POST["cedula"]."','".$_POST["nombres"]."', '".$_POST["apellidos"]."')";
$result = mysql_query($sql);
echo "¡Gracias! Hemos recibido sus datos.\n";
die(mysql_error($link));
}
}
else
{
?>
<form method="post" action="prueba4ingreso.php">
Cedula:<input type="Integer" name="cedula"><br>
Nombres:<input type="Text" name="nombres"><br>
Apellidos:<input type="Text" name="apellidos"><br>
<input type="Submit" name="enviar" value="Aceptar información">
</form>
<?php
}
?>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Alguien podría ayudarme con este script para guardar la Cedula en la base de datos?

Publicado por Victor Gonzalez (4 intervenciones) el 05/11/2006 07:04:11
Primero crea el archivo index.html con este contenido:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>
 
<body>
<form name="register" method="POST" action="register.php">
      <div align="left">
        <table border="0" cellpadding="2">
          <tr>
            <td width="17">Cedula:</td>
            <td width="212"><div align="center">
                <input type="text" name="cedula" size="30" />
            </div></td>
          </tr>
          <tr>
            <td>Nombre:</td>
            <td><div align="center">
                <input type="text" name="nombre" size="30" />
            </div></td>
          </tr>
          <tr>
            <td>Apellido:</td>
            <td><div align="center">
                <input type="text" name="apellido" size="30" />
            </div></td>
          </tr>
          <tr>
            <td><input type="hidden" name="submit" value="true" /></td>
          </tr>
          <tr>
            <td align="center" colspan="2"><p>
                <?php error_reporting (E_ERROR | E_WARNING | E_PARSE);
if (strlen($content) > 0) { echo "<font color='white'>$content</font>"; } ?>
                <input name="image" type="image" src="register.png" />
              </p>            </td>
          </tr>
        </table>
		 <br />
      </div>
    </form>
</body>
</html>

Despues crea el archivo register.php y pon esto:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
 
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '123';
$mysql_db = 'datos_personales';
 
$link = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db, $link);
 
function show_error($message)
{
	$content = $message;
	require_once('index.html');
	exit();
}
 
if (isset($_POST['submit']))
{
	// Asegurarse de la informacion //
	foreach ($_POST as $value)
	{
		if (strlen($value) <= 0)
		{
			show_error('Debes rellenar todos los datos');
		}
	}
 
	$cedula = mysql_escape_string($_POST['cedula']);
	$nombre = mysql_escape_string($_POST['nombre']);
	$apellido = mysql_escape_string($_POST['apellido']);
 
 
 
 
	// Asegurarse que no existe esa cedula en la database //
	$sql = "SELECT * FROM `datos_personales` WHERE `cedula` = '$cedula'";
	$result = mysql_query($sql);
	if (mysql_num_rows($result))
	{
		show_error('Ya existe esa cedula en la database');
	}
 
	// Insertar datos //
	$sql = "INSERT INTO `datos_personales` (`cedula`, `nombre`, `apellido`)
			VALUES ('$cedula', '$nombre', '$apellido')";
	$result = mysql_query($sql);
	if (!$result)
	{
		show_error('Hubo un error al intentar insertar tu cedula!');
	} else {
		show_error('Cedula añadida con exito');
	}
} else {
	require_once('index.html');
}
 
?>


P.D.: Asegurate de tener un boton llamado register.png para que se vea correctamente.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar