JonaGuitar Posted January 14, 2009 Report Share Posted January 14, 2009 ======================================== CONEXION ====================================== <?php function Conectarse() { if (!($link=mysql_connect("localhost","root","jona"))) { echo "Error conectando a la base de datos."; exit(); } if (!mysql_select_db("futuresports",$link)) { echo "Error seleccionando la base de datos."; exit(); } return $link; } ?> ====================================================================================== ======================================== AGREGAR ======================================= <?php include("conexion.php"); $link=Conectarse(); $nombre=$_GET['txtNombre']; $rut=$_GET['txtRut']; $num_celular=$_GET['txtNumCelular']; $correo_electronico=$_GET['txtMail']; $edad=$_GET['selectEdad']; $contrasena=$_GET['txtContrasena']; mysql_query("insert into cliente (nombre, rut, num_celular,correo_electronico, edad, contrasena) values('$nombre','$rut','$num_celular','$correo_electronico','$edad','$contrasena')",$link); ?> ====================================================================================== =========================================== BORRAR ===================================== <?php include("conexion.php"); $link=Conectarse(); $result=mysql_query("select * from cliente",$link); ?> <?php while($row = mysql_fetch_array($result)) { printf("<tr><td> %s</td><td> %s</td><td> %s</td><td> %s</td><td> %s </td><td> <a href=\"elimina.php?rut_seleccionado=%d\">Borrar</a></td></tr>", $row["rut"], $row["nombre"], $row["num_celular"], $row["correo_electronico"], $row["edad"], $row["rut"]); } mysql_free_result($result); mysql_close($link); ?> ----------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- BORRAR EN BASE DE DATOS --------------------------------------------------------------------------------------- <?php include("conexion.php"); $link=Conectarse(); mysql_query("delete from cliente where rut = $rut_seleccionado",$link); //header("Location: borrar.php"); ?> ====================================================================================== ================================ ACTUALIZAR BASE DE DATOS================================== <?php if (isset($_POST['Buscar'])) { include("conexion.php"); function esta() { $link=Conectarse(); $rut_seleccionado= $_REQUEST['rut']; $result=mysql_query("select * from cliente where rut = $rut_seleccionado",$link); $row = mysql_fetch_array($result); if ($row==0) { mysql_close($link); return false; } else { mysql_close($link); return true; } } function resultado() { $link=Conectarse(); $rut_seleccionado= $_REQUEST['rut']; $result=mysql_query("select * from cliente where rut = $rut_seleccionado",$link); $row = mysql_fetch_array($result); mysql_close($link); return $row; } } ?> ================================================================================================== ==================================== ACTUALIZAR ======================================== <? if (!$_POST) { ?> <FORM ACTION="ActualizaClave.php" method="POST"> <TABLE width="525" height="60" border=0 cellpadding="0" cellspacing="0"> <TR> <TD width="190" class="Estilo6">Rut</TD> <TD width="10" class="Estilo6">:</TD> <TD width="325"><input type="text" name="rut" id="rut"></TD> </TR> <TR> <TD class="Estilo6">Contraseña</TD> <TD class="Estilo6">:</TD> <TD><input type="password" name="contrasena" id="contrasena"></TD> </TR> </TABLE> <INPUT TYPE="submit" NAME="Buscar" VALUE="Buscar"> <INPUT TYPE="submit" NAME="Actualizar" VALUE="Actualizar"> <INPUT TYPE="reset" NAME="Limpiar" VALUE="Limpiar"> </FORM> <? } else { if (isset($_POST['Buscar'])) { include("ProcesaActualizaClave.php"); $respuestaamt=esta(); if ($respuestaamt) { $respuesta = resultado(); ?> <FORM ACTION="ActualizaClave.php" method="POST"> <TABLE width="523" height="60" border=0 cellpadding="0" cellspacing="0"> <TR> <TD width="188" class="Estilo6">Rut</TD> <TD width="10" class="Estilo6">:</TD> <TD width="325"><input name="rut" type="text" id="rut" value= "<? echo $respuesta["rut"];?>" ></TD> </TR> <TR> <TD class="Estilo6">Contraseña</TD> <TD class="Estilo6">:</TD> <TD><input name="contrasena" type="password" id="contrasena" value= "<? echo $respuesta["contrasena"];?>" ></TD> </TR> </TABLE> <INPUT TYPE="submit" NAME="Buscar" VALUE="Buscar"> <INPUT TYPE="submit" NAME="Actualizar" VALUE="Actualizar"> <INPUT TYPE="reset" NAME="Limpiar" VALUE="Limpiar"> </FORM> <? } else { ?> <FORM ACTION="ActualizaClave.php" method="POST"> <TABLE width="520" height="59" border=0 cellpadding="0" cellspacing="0"> <TR> <TD width="185" class="Estilo6">Rut</TD> <TD width="10" class="Estilo6">:</TD> <TD width="325"><input type="text" name="rut" id="rut"></TD> </TR> <TR> <TD class="Estilo6">Contraseña</TD> <TD class="Estilo6">:</TD> <TD><input type="password" name="contrasena" id="contrasena"></TD> </TR> </TABLE> <p><INPUT TYPE="submit" NAME="Buscar" VALUE="Buscar"> <INPUT TYPE="submit" NAME="Actualizar" VALUE="Actualizar"> <INPUT TYPE="reset" NAME="Limpiar" VALUE="Limpiar"> </p> <p class="Estilo10">El cliente no existe </p> </FORM> <? } //Fin esta o no } //Fin if busca if (isset($_POST['Actualizar'])) { include("conexion.php"); $link=Conectarse(); $rut = chop($_POST['rut']); $contrasena = chop($_POST['contrasena']); mysql_query("update cliente set contrasena='$contrasena' where rut ='$rut'",$link); mysql_close($link); ?> <html> <body> <FORM ACTION="ActualizaClave.php" method="POST"> <TABLE width="523" height="58" border=0 cellpadding="0" cellspacing=""> <TR> <TD width="187" class="Estilo6">Rut</TD> <TD width="10" class="Estilo6">:</TD> <TD width="326"><input type="text" name="rut" id="rut"></TD> </TR> <TR> <TD class="Estilo6">Contraseña</TD> <TD class="Estilo6">:</TD> <TD><input type="password" name="contrasena" id="contrasena"></TD> </TR> </TABLE> <INPUT TYPE="submit" NAME="Buscar" VALUE="Buscar"> <INPUT TYPE="submit" NAME="Actualizar" VALUE="Actualizar"> <INPUT TYPE="reset" NAME="Limpiar" VALUE="Limpiar"> </FORM> <hr> </body> </html> <? } //Fin Actualiza } //Fin if Post ?> </FORM> ================================================================================================== ========================================= LOGIN ======================================== <? include("conexion.php"); $link=Conectarse(); $rut=$_GET['txtRut']; $contrasena=$_GET['txtPassword']; $result=mysql_query("SELECT rut, contrasena FROM cliente WHERE rut='$rut' AND contrasena='$contrasena'", $link); if(mysql_num_rows($result) == 1) { echo "Bienvenido(a):"; } else { echo "Error de Usuario y/o Contraseña"; } ?> ================================================================================================= ================================ CONSULTAS A DATOS (MOSTRAR TODO) =========================== 1.- SE HACE LA CONSULTA <?php include("conexion.php"); $link=Conectarse(); $result=mysql_query("select * from cliente",$link); //$result=mysql_query("select nombre, rut, num_celular, correo_electronico, edad from cliente where rut='$rut'",$link); ?> 2.- SE REALIZA LA TABLA CON CAMPOS A MOSTRAR <table width="777" height="64" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="148" bgcolor="#F0F0F0"><div align="center" class="Estilo10"> <div align="left">Nombre</div> </div></td> <td width="153" bgcolor="#F0F0F0"><div align="center" class="Estilo10"> <div align="left">Rut</div> </div></td> <td width="143" bgcolor="#F0F0F0"><div align="center" class="Estilo10"> <div align="left">N° Celular</div> </div></td> <td width="209" bgcolor="#F0F0F0"><div align="center" class="Estilo10"> <div align="left">Email</div> </div></td> <td width="124" bgcolor="#F0F0F0"><div align="center" class="Estilo10"> <div align="left">Edad</div> </div></td> </tr> 3.- SE REALIZA LA LLAMADA A LOS DATOS PARA MOSTRARLOS EN LA TABLA <?php while($row = mysql_fetch_array($result)) { printf("<tr><td> %s</td> <td> %s </td> <td> %s</td> <td> %s </td> <td> %s </td></tr>", $row["nombre"], $row["rut"], $row["num_celular"], $row["correo_electronico"], $row["edad"]); } mysql_free_result($result); mysql_close($link); ?> ================================================================================================== Link to comment Share on other sites More sharing options...
karloncho_20 Posted January 14, 2009 Report Share Posted January 14, 2009 nicagando me leo toa la wea pone una descripcion de el script pos wn porke de otro modo no me leo nada de eso saludos! Link to comment Share on other sites More sharing options...
HoliBlack Posted January 14, 2009 Report Share Posted January 14, 2009 hola buen aporte compadre pero has oido hablar de "DOCUMENTACION DE CODIGO"!!! es para una mejor lectura al codigo asi se entiende mejor saludos compartiendo con el socio de arriva :salucita: Link to comment Share on other sites More sharing options...
JonaGuitar Posted January 14, 2009 Author Report Share Posted January 14, 2009 cabros les pido mil disculpas por no documentar mil pero mil disculpas Link to comment Share on other sites More sharing options...
ichoisrael Posted January 17, 2009 Report Share Posted January 17, 2009 Esto no es un manual pa lo jiles, dice claramente SCRIPT, excelente aporte compadre no pesque a weones flojos, con la descripcion inicial que tiene cada script basta y sobra. Link to comment Share on other sites More sharing options...
ch1l3no Posted January 18, 2009 Report Share Posted January 18, 2009 Esto no es un manual pa lo jiles, dice claramente SCRIPT, excelente aporte compadre no pesque a weones flojos, con la descripcion inicial que tiene cada script basta y sobra. X2 a todo ritmo viejo. Uta que me hubieran servido cuando comence con esto de la webrssss. Les tengo una pregunta, porque no usar procedimientos almacenados para brindar una capa mas de seguridad y modularidad? PD: mysql 5.0 en adelante soporta proc. , funciones y cursores. espero comentarios ... saludos (= Link to comment Share on other sites More sharing options...
puyol Posted July 28, 2009 Report Share Posted July 28, 2009 excelente aporte muchas gracias :banana: :banana: :banana: :banana: :banana: :banana: Link to comment Share on other sites More sharing options...
okinagua Posted July 28, 2009 Report Share Posted July 28, 2009 Muy bueno el aporte, pero yo uso las funciones pasando los valores por parametros, asi es mas general y mas facil de exportar. Saludos Link to comment Share on other sites More sharing options...
hack_the_gamer Posted July 28, 2009 Report Share Posted July 28, 2009 puro sql injected :D es un script basico nomas :D Link to comment Share on other sites More sharing options...
friveracast Posted August 4, 2009 Report Share Posted August 4, 2009 gracias compadre, me va a servir para refrescar la memoria, se agradece el aporte Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now