1 / 21

PRE_LAB

PRE_LAB. Comprobación de datos. is_array($var) : verifica si $var es una serie is_float($numero) : verifica si $numero es un numero de punto flotante is_null($var) : verifica si $var es igual a 0

john
Télécharger la présentation

PRE_LAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PRE_LAB

  2. Comprobación de datos • is_array($var) : verifica si $var es una serie • is_float($numero) : verifica si $numero es un numero de punto flotante • is_null($var) : verifica si $var es igual a 0 • is_numeric($cadena) : verifica si $cadena es una cadena numerica (que seria la que tu quieres de numero) • is_string($cadena) : verifica si $cadena es una cadena (que seria la que tu quieres de texto)

  3. Mensaje alerta • <? • echo " • <script language=\"javascript\"> • alert('El mensaje que quieras'); • </script>"; • ?>

  4. PHP & MYSQL

  5. Importar desde excel • Copiar los siguientes datos a un archivo excel (csv), para luego importar desde phpmyadmin

  6. Helados “aiscrim” Base de datos: aiscrim Tabla: productos

  7. Importar desde excel • Crear siguiente tabla desde phpmyadmin

  8. Venta helados “aiscrim” Base de datos: aiscrim Tabla: ventas

  9. Probemos! • Select nombre from productos where precio_venta=‘100’; • (Muestra centella) • Delete * from productos where marca=‘Bresler’; • (Elimina de la tabla todos los productos Bresler) • Insert into productos (id,nombre,marca,precio_venta) values (104,’crazy’,’Savory’,550); • (Agrega un nuevo producto)

  10. Probemos! • Select * from productos,ventas where nombre=‘centella’ && products.id=ventas.id; • (Muestra todas las ventas de centella) • Select cantidad from productos,ventas where marca=‘Savory’ && products.id=ventas.id; • (Muestra cantidad de todos los productos Savory) • Update productos set precio_venta =‘900’ where nombre=‘Danky’; • (Actualiza el precio del helado Danky)

  11. PHP & MYSQL • ¿Cómo “conectar” PHP y MYSQL?

  12. conexion.php • <? • $dbhost="localhost"; // host del MySQL • $dbusuario="root"; // aqui debes ingresar el nombre de //usuario para acceder a la base • $dbpassword=""; // password de acceso para el usuario //de la linea anterior • $db="helados"; // Seleccionamos la base con //la cual trabajar • $conexion = mysql_connect($dbhost, $dbusuario, $dbpassword); • mysql_select_db($db, $conexion); • ?>

  13. cerrar_conexion.php • <? • mysql_close($conexion); • ?>

  14. Llamar a conexión.php • <? • include "conexion.php"; • //codigo • ?> • ---------------------------------------------------------- • <? • include ("../conexion.php"); • //el archivo conexión está un directorio atrás • ?>

  15. Función “ver.php” • <? • include "conexion.php"; • $result=mysql_query("SELECT * FROM productos ORDER BY `id` ASC", $conexion); • echo" • <center> • <br> • <h1>Listado de productos<h1> • <br> • <table align=\"center\" width=600 border=1> • <tr bgcolor=#FF6600> • <td><b>ID</b></td> • <td><b>Producto</b></td> • <td><b>Marca</b></td> • <td><b>Precio_Venta</b></td>"; • while($row=mysql_fetch_row($result)) • { • echo"<tr align=\"center\"> • <td> $row[0]</td> • <td>$row[1]</td> • <td> $row[2]</td> • <td>$ $row[3]</td> • </tr></center>"; • } • echo"</table>"; • ?>

  16. Función “guardar1.php” • <html> • <body> • <blockquote> • <br> • <h3>Guardar datos en la base</h3> • <form action="guardar2.php" method="post"> • Código:<br> • <input type="int" name="id"> • <br> • Nombre<br> • <input type="text" name="nombre"> • <br> • Marca<br> • <input type="text" name="marca"> • <br> • Precio:<br> • <input type="float" name="precio"> • <br> • <br> • <input type="submit" name="sub" value="Guardar Datos"> • </form> • </body> • </html>

  17. archivo “guardar2.php” • <?php • include "conexion.php"; • $sql="INSERT INTO productos (id, nombre, marca, precio_venta) • VALUES • ('$_POST[id]','$_POST[nombre]','$_POST[marca]','$_POST[precio_venta]')"; • $result = mysql_query($sql); • echo "<h3> Los datos han sido guardados</h3>"; • include "cerrar_conexion.php"; • ?>

  18. Función “ver + actualizar + eliminar’” (ver2.php) • <? • include "conexion.php"; • $result=mysql_query("SELECT * FROM productos ORDER BY `id` ASC", $conexion); • echo" • <center> • <br> • <h1>Listado de productos<h1> • <br> • <table align=\"center\" border=1> • <tr bgcolor=#FF6600> • <td><b>ID</b></td> • <td><b>Producto</b></td> • <td><b>Marca</b></td> • <td><b>Precio_Venta</b></td> • <td><b>Actualizar </td> • <td><b>Eliminar </td>"; • while($row=mysql_fetch_row($result)) • { • echo"<tr align=\"center\"> • <td> $row[0]</td> • <td>$row[1]</td> • <td>$row[2]</td> • <td>$ $row[3]</td> • <td><a href=\”actualizar.php?id=$row[0]\">Actualizar </td> • <td><a href=\”eliminar.php?id=$row[0]\">Eliminar </td> • </tr></center>"; • } • echo"</table>"; • ?> NOMBRE CAMPOS REGISTROS

  19. Función “eliminar.php’” • <?php • include "conexion.php"; • $id=$_GET['id']; • $result=mysql_query("DELETE FROM productos WHERE id = $id",$conexion); • echo " • <html> • <body> • <h3>Los registros han sido eliminados</h3> • </body> • </html>"; • include "cerrar_conexion.php"; • ?>

  20. Función “actualizar.php’” • <?php • include ("../conexion.php"); • $id=$_GET['id']; • if (!isset($_GET["accion"])){ • $result=mysql_query("SELECT * FROM productos WHERE id = $id",$conexion); • $row = mysql_fetch_array($result); • echo"<html> • <head><title>Actualizar datos de la base</title></head> • <body> • <form action=\"actualizar.php?accion=guardar\" method=\"POST\"> • Detalle:<br> • <input type=\"text\" value=\"$row[1]\" name=\"detalle\"><br> • Precio:<br> • <input type=\"float\" value=\"$row[2]\" name=\"precio\"><br> • Precio de venta:<br> • <input type=\"float\" value=\"$row[3]\" name=\"precio_venta\"><br> • <input type=\"hidden\" name=\"id\" value=\"$row[0]\"> • <input type=\"submit\" value=\"Guardar\"> • </form> • </body> • </html>"; }

  21. Función “actualizar.php (continuación)’” • elseif($_GET["accion"]== "guardar" ) • { • $detalle=$_POST['detalle']; • $precio=$_POST['precio']; • $id=$_POST['id']; • $precio_venta=$_POST['precio_venta']; • $result=mysql_query("UPDATE productos SET detalle='$detalle', precio='$precio', precio_venta='$precio_venta' WHERE id = $id",$conexion); • echo" • <html> • <body> • <h3>Los registros han sido actualizados</h3> • </body> • </html>"; • } • include "cerrar_conexion.php"; • ?>

More Related