Está en la página 1de 5

<html> <body bgcolor="#cccccc"> <center> <font color="red" size="5"> * Alta de alumnos * </font> <hr size="3" color="blue" width="90%"> <br><br>

<?php $mat=$_POST["mat"]; $nom=$_POST["nom"]; $ap=$_POST["ap"]; $am=$_POST["am"]; $car=$_POST["car"]; $tel=$_POST["tel"]; $cor=$_POST["cor"]; //VALIDAR QUE TODOS LOS DATOS TIENEN INFORMACION if ((strlen($mat)==0) || (strlen($nom)==0) || (strlen($ap)==0) || (strlen($am)==0) || (strlen($car)==0) || (strlen($tel)==0) || (strlen($cor)==0)) { echo "<font color='red' size='5'> Error, TODOS los datos son obligatorios ... </font>"; } else { if (substr($mat,0,2) != "A0") echo "<font color='red' size='5'> Error, la matrcula debe iniciar con A0 ... </font>"; else {

if (strlen($mat) != 9) echo "<font color='red' size='5'> Error, la matrcula debe tener 9 dgitos forzosos ... </font>"; else { $sw_error=0; $ctrl=2; while ($ctrl < strlen($mat)) { if (($mat[$ctrl]<'0') || ($mat[$ctrl] >'9')) { $sw_error=1; break; } $ctrl++; } // CICLO PARA BUSCAR LETRAS EN LA MATRICULA if ($sw_error==1) echo "<font color='red' size='5'> Error, la matrcula tiene smbiolos o letras invalidos ... </font>"; else { if (strlen($car)<3) echo "<font color='red' size='5'> Error, la carrera debe tener al menos 3 caracteres ... </font>"; else { $sw_error=0; $ctrl=0; while ($ctrl < strlen($tel))

{ if (($tel[$ctrl]<'0') || ($tel[$ctrl] >'9')) { $sw_error=1; break; } $ctrl++; } // CICLO PARA BUSCAR LETRAS EN EL TELEFONO. if ($sw_error==1) echo "<font color='red' size='5'> Error, el telfono tiene letras o caracteres invalidos ... </font>"; else { if (strlen($tel) < 10) echo "<font color='red' size='5'> Error, el telfono debe tener 10 dgitos forzoso ... </font>"; else { $sw_tiene_arroba=0; $ctrl=0; while ($ctrl < strlen($cor)) { if ($cor[$ctrl]=='@') { $sw_tiene_arroba=1;

break; } $ctrl++; } // CICLO PARA BUSCAR LA PINC... ARROBA ... if ($sw_tiene_arroba == 0) echo "<font color='red' size='5'> Error, el correo debe llevar una @ forzoso... </font>"; else { $cone_serv=mysql_connect("localhost","root",""); $cone_bd = mysql_select_db("escuela",$cone_serv); if ($cone_bd != 1) echo "<font color='red' size='5'> Error, no hay conexin con la base de datos... </font>"; else { $sql=mysql_query("SELECT * FROM alumnos WHERE mat_al='$mat'"); $reg=mysql_fetch_object($sql); if ($reg != mysql_fetch_array($sql)) echo "<font color='red' size='5'> Error, la matrcula se DUPLICA en la base de datos... </font>"; else

{ mysql_query("INSERT INTO alumnos VALUES('$mat','$nom', '$ap', '$am', '$car','$tel', '$cor')"); echo "<font color='green' size='5'> Los datos de $mat han sido GRABADOS ... </font>"; } // TERMINA VALIDACION DE QUE NO SE DUPLICA MATRICULA EN BASE DE DATOS } // TERMINA VALIDACION DE CONEXION A LA BASE DE DATOS } // TERMINA VALIDACIONE DE QUE TENGA ARROBA EN EL CORREO } // TERMINA LA VALIDACION DE 10 DIGITOS FORZOSO } // TERMINA VALIDACION DE BUSCAR LETRAS EN EL TELEFONO } // TERMINA VALIDACION DE QUE LA CARRERA TENGA 3 4 CARACTERES } // TERMINA VALIDACION DE QUE LA MATRICULA TENGA SOLO NUMEROS } // TERMINA VALIDACION DE QUE LA MATRICULA TENGA 9 CARACTERES } // TERMINA VALIDACION DE QUE LA MATRICULA INICIE CON A0 } // TERMINA VALIDACION DE QUE TODOS LOS VALORES TENGAN DATOS ?> </center> </body> </html>

También podría gustarte