0% encontró este documento útil (0 votos)
173 vistas38 páginas

Proyecto Web Con PHP Y Mysql: Desarrollar Soluciones de Negocio A Través de La Plataforma Libre Web Del PHP y Mysql

Este documento describe un curso sobre el desarrollo de proyectos web utilizando PHP y MySQL. Explica cómo instalar el software necesario como AppServ y realiza una introducción a conceptos clave como plataforma web, protocolos de comunicación y lenguajes como PHP, MySQL y HTML.

Cargado por

Nestor Vera
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
173 vistas38 páginas

Proyecto Web Con PHP Y Mysql: Desarrollar Soluciones de Negocio A Través de La Plataforma Libre Web Del PHP y Mysql

Este documento describe un curso sobre el desarrollo de proyectos web utilizando PHP y MySQL. Explica cómo instalar el software necesario como AppServ y realiza una introducción a conceptos clave como plataforma web, protocolos de comunicación y lenguajes como PHP, MySQL y HTML.

Cargado por

Nestor Vera
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd

PROYECTO WEB CON PHP Y MYSQL

http://www.phpya.com.ar
OBJETIVO DE CURSO:

Desarrollar soluciones de negocio a través de la plataforma libre web del


Php y Mysql.

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 1
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

INTRODUCCIÓN

Un proyecto web es un emprendimiento temporal realizado para crear un

producto o servicio único que haciendo uso de una plataforma “web”

busca conseguir un objetivo específico.

El enfoque de proyecto web busca superar la visión de “diseñar una

página web”. Se trata de concebir el desarrollo de un solución web, como

un proyecto que debe ser formulado, gestionado y evaluado.

El desarrollo de sitios web suele estar prejuiciadamente

relacionado con informalidad, pues la gestión

de proyectos web no ha sido una práctica común. No

obstante la propuesta de desarrollar soluciones web

desde un enfoque de administración de proyectos

busca evitar errores futuros, problemas con proveedores

e incluso disputas legales.

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 2
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
PLATAFORMA WEB

Una plataforma web es el conjunto de tecnologías, estándares y protocolos que permiten que
las páginas web como parte de un sitio web puedan ser desplegadas en el navegador del
usuario para fines que podrían ir desde simple información hasta el más sofisticado proceso
de automatización remota.

La terminología web, hace referencia al soporte que da esta plataforma al sistema de


distribución de información basado en hipertexto. Para asegurar que un proyecto de
cualquier tipo: educativo, gubernamental, comercial, publicitario, etc. soportado por un
plataforma web funcione correctamente, es indispensable entender que esta incluye tres
componentes:

• Servidor web

• Protocolos de comunicación

• Navegador - usuario final

La siguiente ilustración muestra estos componentes y otros tecnologías relacionadas.

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 3
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
ACRÓNIMOS
PHP: es un acrónimo recursivo que significa PHP Hypertext Pre-processor (inicialmente PHP
Tools, o,Personal Home Page Tools). Es un lenguaje de programación interpretado, diseñado
originalmente para la creación de páginas web dinámicas. Es usado principalmente en
interpretación del lado del servidor.

MySQL: siglas de My Structured Query Language, es decir Mi Lenguaje de Consulta


Estructurado. Es un sistema de gestión de base de datos relacional, multihilo y multiusuario.
Es uno de los sistmas con mayor cantidad de instalaciones en el mundo.

P2P: del inglés Peer to Peer, es decir red de pares o red punto a punto. Es una red de
computadoras en la que todos o algunos aspectos funcionan sin clientes ni
servidores fijos, sino una serie de nodos que se comportan como iguales entre sí.

TCP/IP: son las siglas en inglés de TransmissionControl Protocol / Internet Protocol es decir
Protocolo de Control de Transmisión y Protocolo de Internet. Son los dos protocolos
fundamentales de Internet. TCP es un protocolo de comunicación orientado a conexión y
fiable del nivel de transporte. IP por su parte es un protocolo no orientado a conexión usado
tanto por el origen como por el destino para la comunicación de datos a través de una red de
paquetes conmutados.

UDP: de User Datagram Protocol. Es un protocolo delnivel de transporte basado en el


intercambio de datagramas (Paquete de datos). Permite el envío de
datagramas a través de la red sin que se haya establecido previamente una conexión.

IPv6: es una versión del protocolo Internet Protocol (IP), diseñada para reemplazar a IPv4,
que actualmenteestá implementado en la gran mayoría de dispositivos que acceden a
Internet.

XML: siglas en inglés de eXtensible Markup Language, es decir Lenguaje de Marcas Extensible,
es un metalenguaje extensible de etiquetas, por lo tanto no es realmente un lenguaje en
particular, sino una manera de definir lenguajes para diferentes necesidades.

XHTML: acrónimo en inglés de eXtensible HypertextMarkup Language, es decir, Lenguaje


Extensible de Marcado de Hipertexto. Su objetivo es avanzar en el proyecto del W3C de
lograr una web semántica, donde la información, y la forma de presentarla estén claramente
separadas.

CSS: del inglés Cascading Style Sheets, significa Hojas de Estilo en Cascada. Es un lenguaje
usado para definir la presentación de un documento estructurado escrito en HTML o XML.

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 4
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 5
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
SESION 01: Instalacion De Software Y Generalidades

SOFTWARE REQUERIDO: APPSERV – Paquete de software que contiene los siguientes


programas:

Además permite la instalación, configuración y uso automático de los componentes.

INSTALACION DE APPSERV

 Pantalla de inicio de instalación

 Definiendo la ubicación de la instalación

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 6
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

 Definiendo los programas a instalar (Seleccionar todos)

 Definiendo los datos del servidor, siempre establecer “localhost” y el puerto “80”, el
email es referencial.

 Definiendo el password de usuario ROOT (principal), en este caso le establecemos


“123”

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 7
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
 Esperar la instalación:

 Si aparece alguna de estas ventanas:

 Siempre click en la opción “desbloquear”, es para que el Firewall de Windows no


bloquee el acceso.

 Finalizando la instalación:

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 8
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

 Como comprobamos que la instalación es correcta:

 Y veremos el siguiente icono:

 De estar en flecha de color verde indica que esta corriendo sin problemas.

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 9
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

 Para mayor verificación digitar: http://localhost en un navegador:

 Eso indica que el apache está corriendo, de presentar algún conflicto con el Internet
Informatión Server basta entrar a la línea de comando (DOS) y digitar el comando:

“iisreset -stop"

 Esto detendrá el servicio del IIS y se deberá reactivar el servicio de apache a través del
monitor que se encuentra en la barra de tareas.

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 10
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
UBICACIÓN DE ARCHIVOS

 Para la creación de archivos del tipo .php es necesario guardarlos en la siguiente


ubicación:

Seleccionar esa carpeta y crear una subcarpeta


dentro, por ejmplo la carpeta “data”

 Todos los archivos se grabaran en esa ubicación.

Significado:

.round = (redondea a valores enteros)


$_REQUEST = (recuperar la informacion del form anterior)

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 11
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 12
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

RECORDANDO HTML y PHP

ARCHIVO1.HTM

<html>
<!--
HTML 3.2
Document type as defined on http://www.w3.org/TR/REC-html32
-->
<head>
<title>Title here!</title>
</head>
<body>

<form action="archivo2.php" method="post">


Digite de cuantos GB de capacidad es un Unidad de almacenamiento portatil:
<input type="text" name="txtunidad" />
<input type="submit" name="btncalcula" value="Calcular Canciones" />
</form>

</body>
</html>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 13
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

ARCHIVO2.PHP

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">


<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php

$capacidad = $_REQUEST["txtunidad"];
$total = ($capacidad * 1024) / 3.5;
echo "La cantidad de archivos MP3 que almacena es aproximada es " .round($total);

?>
</body>
</html>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 14
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 15
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

RECORDANDO HTML y PHP

ARCHIVO3.HTM

Promedio de notas:

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">


<html>
<head><title> PROMEDIO DE NOTAS</title></head>
<Body>

<form action="archivo3.php" method="post">


Ingrese las 3 notas:<p>
Nota1:
<input type="text" name="txtn1" /><p>
Nota2
<input type="text" name="txtn2" /><p>
Nota3
<input type="text" name="txtn3" /><p>
<input type="submit" name="btncalcula" value="Calcular Notas" />
</form>

</body>
</html>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 16
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

Archivo4.php

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">


<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php

$capacidad1 = $_REQUEST["txtn1"];
$capacidad2 = $_REQUEST["txtn2"];
$capacidad3 = $_REQUEST["txtn3"];
$total = ($capacidad1+$capacidad2+$capacidad3)/ 3;
echo "El promedio final es: " .round($total);

?>
</body>
</html>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 17
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 18
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

PAGINA1.PHP

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">


<html>
<head>
<title>Pagina par e impar</title>
</head>
<body>
<?php

If (isset($_POST['btnevaluar']))
{
$numero=$_REQUEST['txtnum'];
if ($numero %2==0)
{
echo "el numero ingresado es par";
}
else
{
echo "el numero ingresado es impar";
}
}
else
{
echo "<form action='pagina1.php' method='POST'>";
echo "digite numero<input type='text' name='txtnum'/>";
echo "<input type='submit' name='btnevaluar'value='evaluar numero'/>";
echo "</form>";
}

?>
</body>
</html>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 19
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 20
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
METODO:

$_POST
Contiene valores de un objeto que a sido
enviado de otra forma.
$_REQUEST

FUNCION:

Evalúa la existencia de cierto valor


Iseet variable

FUNCIONES MAS EMPLEADAS:

 Mysql_connect ([servidor],[usuario],[clave])
 Mysql_select _db ([b.d],[conexion])
 Mysql_query ([cons sql],[conexion])
 Mysql_num_rows ([query])
 Mysql_result ([query],[num.fila],[nombre de campo])

NOTA:

Connect.- Establece con que vamos a trabajar


Select.- definir con que B.D trabajamos
Query.- define nuestra consulta
Num.-
Result.- Devuelve en dato especifico de toda una tabla

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 21
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 22
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

SCRIP BASICO DE CONEXIÓN

CONEXIÓN.PHP

<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php

$conexion=mysql_connect("localhost","root","123");
mysql_select_db("dbcolegio",$conexion);
$datos=mysql_query("select * from alumnos",$conexion);
$total=mysql_num_rows($datos);
{
echo mysql_result($datos,$xx,"codigo");
echo mysql_result($datos,$xx,"nombres");
echo mysql_result($datos,$xx,"apellidos");
}

?>
</body>
</html>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 23
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
EN MYSQL CREAR LA BASE DE DATOS COLEGIO

 Creación de la base de datos colegio - tabla alumnos - campos - insertar registro

mysql> create database dbcolegio;


Query OK, 1 row affected (0.02 sec) create database dbcolegio;
use dbcolegio;
mysql> use dbcolegio; código int(4),
Database changed nombres varchar(50),
mysql> create table alumnos apellidos varchar(50)
-> ( );
-> codigo int(4), insert into alumnos values
-> nombres varchar(50), ('1','Ivan','Tarqui',’Huaman’;
-> apellidos varchar(50)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> insert into alumnos values('1','Ivan','Tarqui',’Huaman’;
Query OK, 1 row affected (0.00 sec)

consulta:

 En el explorador poner la siguiente dirección:

http://localhost/ivan/conexion.php

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 24
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 25
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
24/08/2011
EN MYSQL CREAR LA BASE DE DATOS NEGOCIOS

CODIGO DE MYSQL:

Create database dbnegocios;


Use dbnegocios;
Create table productos
(
Cod_pro int(4),
Nom_pro varchar(35),
Pre_pro float(8,2),
Sto_pro int(4)
);
Insert into productos values(100,’Aceite Primor x1Lt’,4.50,35);
Insert into productos values(101,’Leche Ideal x 22ml’,2.40,105);

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 26
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

CONEXIÓN.PHP

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">


<html>
<head>
<title>Conexion</title>
</head>
<body>
<?php

$conexion=mysql_connect("localhost","root","123");
mysql_select_db("dbnegocios",$conexion);

?>
</body>
</html>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 27
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

PRODUCTOS.PHP

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">


<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php

include('conexion.php');
$datos=mysql_query("select * from productos");
$total=mysql_num_rows($datos);
echo "<h1>Registro General De Productos</h1>";
echo "<table border=2>";
echo "<tr><th>Codigo</th><th>Nombre</th><th>Precio</th><th>Stock</th></tr>";
for ($x=0;$x<$total;$x++)
{
$aa=mysql_result($datos,$x,"cod_pro");
$bb=mysql_result($datos,$x,"nom_pro");
$cc=mysql_result($datos,$x,"pre_pro");
$dd=mysql_result($datos,$x,"sto_pro");

echo "<tr>";
echo "<td>$aa</td>";
echo "<td>$bb</td>";
echo "<td>$cc</td>";
echo "<td>$dd</td>";
echo "</tr>";
}
echo "</table>";
echo "Total de Productos Registrados:".$total;

?>
</body>
</html>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 28
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 29
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 30
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
http://192.168.1.224/data/productos.php (para ver la base de datos)

 Corremos nuestra linea de comandos y creamos una base de datos en Mysql

CODIGO: Crear la base de datos DBTIENDA

Create database dbtienda;


Use dbtienda;
Create table productos
(
Cod_pro int(6)not null primary key auto increment,
Nom_pro varchar(50),
Pre_pro float(8,2),
Sto_pro int(4)
);

CODIGO_ Insertar Registro ala Base de datos DBTIENDA

Insert into productos values(null,”Aceite Primor x 1Lt”,4.40,72);


Insert into productos values(null,”Leche Ideal x Tarro Gr”,3.20,15);
Insert into productos values(null,”AcFideos Molitalia x 500 Mg”,1.20,88);

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 31
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
 Crearemos un Script de conexión sencillo, conexión.php
CONEXIÓN.PHP

<?php
$cone = mysql_connect("localhost","root","123");
mysql_select_db('dbtienda',$cone);
?>

 Crearemos la pagina productos.php donde visualizamos el detalle de todos los


productos.

PRODUCTOS.PHP
<?php
include("conexion.php");
$datos = mysql_query("select * from productos");
$total = mysql_num_rows($datos);
echo "<center>";
echo "<h1>Registro General De Productos</h1> <p>";
echo "<table border=3>";
echo "<tr><th></th>";
echo "<th></th>";
echo "<th>Codigo</th>";
echo "<th>Nombre</th>";
echo "<th>Precio</th>";
echo "<th>Stock</th></tr>";
for($x = 0; $x<$total;$x++)
{
echo"<tr>";
echo "<td><a href='modificar.php?cod=". mysql_result($datos, $x, "cod_pro")
."'>Modificarx</a></td>";
echo "<td><a href='eliminar.php?cod=". mysql_result($datos, $x, "cod_pro")
."'>Eliminar</a></td>";
echo "<td>". mysql_result($datos, $x, "cod_pro"). "</td>";
echo "<td>". mysql_result($datos, $x, "nom_pro"). "</td>";
echo "<td>". mysql_result($datos, $x, "pre_pro"). "</td>";
echo "<td>". mysql_result($datos, $x, "sto_pro"). "</td>";
echo"</tr>";
}
echo "</table";
echo "<p><a href='nuevo.php'>Nuevo Producto</a>";
echo "</center>";
?>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 32
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
 Crearemos la pagina modificar.php donde visualizamos el detalle de todos los
productos y podemos moficiarlos.

MODIFICAR.PHP

<?php
include("conexion.php");
if(isset($_POST['btnmodificar']))
{
$a = $_REQUEST['txtcodigo'];
$b = $_REQUEST['txtnombre'];
$c = $_REQUEST['txtprecio'];
$d = $_REQUEST['txtstock'];
mysql_query("update productos set nom_pro = '" .$b. "', pre_pro=" .$c. ", sto_pro=".$d.
" where cod_pro = ".$a);
echo "<script>alert('Modificacion fue satisfactoria');</script>";
echo "<script>window.location='productos.php';</script>";
}
else
{
$codigo=$_REQUEST["cod"];
$datos = mysql_query("select * from productos where cod_pro = " . $codigo);
echo "<h1>MODIFICAR</h1><p>";
echo "<form action='modificar.php' method='post'>";
echo "codigo: <input type='text' name='txtcodigo' readonly='readonly'
value='".mysql_result($datos,0,'cod_pro')."'> <br>";
echo "nombre: <input type='text' name='txtnombre' value='".
mysql_result($datos,0,'nom_pro')."'> <br/>";
echo "precio: <input type='text' name='txtprecio' value='".
mysql_result($datos,0,'pre_pro')."'> <br/>";
echo "Stock: <input type='text' name='txtstock' value='".
mysql_result($datos,0,'sto_pro')."'><br/>";
echo "<input type='submit' name='btnmodificar' value='modificar datos' />";
echo "</form>";
}
?>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 33
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

NUEVO.PHP

<?php
include("conexion.php");
if(isset($_POST['btngrabar']))
{
$b= $_REQUEST['txtnombre'];
$c= $_REQUEST['txtprecio'];
$d= $_REQUEST['txtstock'];
mysql_query("insert into productos values(null, '" .$b. "'," .$c. ", ".$d. ")");
echo "<script>alert('Datos fueron Grabados');</script>";
echo "<script>window.location='productos.php';</script>";
}
else
{
$cons = mysql_query("select max(cod_pro) from productos");
echo "<h1>NUEVO PRODUCTO</h1><p>";
echo "<form action='nuevo.php' method='post'>";
echo "codigo: <input type='text' name='txtcodigo' value='".(mysql_result($cons,
0,0)+1)."'><br/>";
echo "nombre: <input type='text' name='txtnombre'><br/>";
echo "precio: <input type='text' name='txtprecio'><br/>";
echo "stock: <input type='text' name='txtstock'><br/>";
echo "<input type='submit' name='btngrabar' value='Grabar Datos' />";
}
?>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 34
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

ELIMINAR.PHP

<script languaje='JavaScript'>
function cancela()
{
alert('Eliminacion fue cancelada');
window.location = 'productos.php';
}
</script>

<?
include("conexion.php");
if(isset($_POST['btneliminar']))
{
$a = $_REQUEST['hdncodigo'];
mysql_query("delete from productos where cod_pro=". $a);
echo "<script>alert('Producto fue eliminado');</script>";
echo "<script>window.location='productos.php';</script>";
}
else if(isset($_POST['btncancelar']))
{
echo "<script>alert('Eliminacion se cancelo');</script>";
echo "<script>window.location='productos.php';</script>";
}
else
{
$cons = mysql_query("select * from productos where cod_pro=".$_REQUEST['cod']);
echo "<h1>ELIMINAR PRODUCTO</h1><p>";
echo "¿Esta seguro de eliminar los datos del producto ".mysql_result($cons,0, 'nom_pro')."?";
echo "<form action='eliminar.php' method='post'>";
echo "<input type='hidden' name='hdncodigo value='" .mysql_result($cons,0, 'cod_pro')."'>";
echo "<input type='submit' name='btneliminar' value='Eliminar datos' />";
echo "<input type=button' name='btncancelar' value='Cancelar eliminacion' onclick='cancela()' />";
echo "</form>";
}

?>

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 35
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

CORRER EL PROGRAMA

Hacemos clic en MODIFICAR:

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 36
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar
Una vez terminado de modificar hacer clic en NUEVO PRODUCTO

Hacemos clic en nuevo:

Clic en grabar datos

Ver lo que se ah agregado:

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 37
PROYECTO WEB CON PHP Y MYSQL
http://www.phpya.com.ar

Autor: Ivan Tarqui Huaman


Correo: [email protected] Página 38

También podría gustarte