PHP Y MYSQL

ARCHIVO DE CONEXIÓN:

<?php
$host="127.0.0.1";
$usuario="root";
$password="quice85";
$conectar=mysql_connect($host,$usuario,$password);
mysql_select_db("systemprog",$conectar);
?>

ARCHIVO DE CONEXIÓN:

<head>
<title> Programa de punto de venta</title>
</head>
<body bgcolor="#888888" text="#aaaa00" topmargin=20 background="fondo.jpg">
<center>
<img src="head.jpg" height="200" width="1000">
<h1>
Sistema de Ventas
</h1>
<hr>
<form action="insertar.php" method="POST">
<table border="2">
<tr><td>Producto</td><td>Usuario</td><td>Fecha</td><td>Cantidad</td><td>Precio</td></tr>
<tr>
<td><input type="text" name="produc" size=15></td>
<td><input type="text" name="usua" size=15></td>
<td><input type="text" name="fecha" size=15></td>
<td><input type="text" name="cant" size=15></td>
<td><input type="text" name="prec" size=15></td>
</tr>
<tr><td colspan=2 align="center"><input type="submit" name="guar" value="Enviar"></td>
<td align="center">*---------------*</td>
<td colspan=2 align="center"><input type="reset" name="borrar" value="Borrar"></td>
</tr>
</table>
</form>
</body>

ARCHIVO DE INSERCIÓN:

<?php
$producto1=$_POST['produc'];
$usuario1=$_POST['usua'];
$fecha1=$_POST['fecha'];
$cantidad1=$_POST['cant'];
$precio1=$_POST['prec'];
include("conect.php");
$insert="insert into ventas (productos,cantidad,precio,fecha,usuario) values 
('$producto1','$cantidad1','$precio1','$fecha1','$usuario1')";
mysql_query($insert,$conectar);
header("Location: index.php");
?>


Creación de tres tablas con la relación foreign key en donde la tabla empleados y productos son las principales:


quice85@quice85-laptop:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 169
Server version: 5.1.63-0ubuntu0.10.04.1 (Ubuntu)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database puntopascual;
Query OK, 1 row affected (0.00 sec)

mysql> use puntopascual;
Database changed
mysql> create table empleados(clave int(8)primary key,empleado varchar(35)not null,puesto varchar(25));
Query OK, 0 rows affected (0.06 sec)

mysql> create table productos(codigo int(8)primary key,producto varchar(25)not null,precio float(15,2)not null);
Query OK, 0 rows affected (0.07 sec)

mysql> create table ventas(id int(10)primary key auto_increment,clave_e int(8)not null,codigo_p int(8)not null,cantidad int(10)not null,foreign key(clave_e) references empleados(clave),foreign key (codigo_p)references productos(codigo));
Query OK, 0 rows affected (0.09 sec)

mysql> describe empleados;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| clave    | int(8)      | NO   | PRI | NULL    |       |
| empleado | varchar(35) | NO   |     | NULL    |       |
| puesto   | varchar(25) | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> describe productos;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| codigo   | int(8)      | NO   | PRI | NULL    |       |
| producto | varchar(25) | NO   |     | NULL    |       |
| precio   | float(15,2) | NO   |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> describe ventas;
+----------+---------+------+-----+---------+----------------+
| Field    | Type    | Null | Key | Default | Extra          |
+----------+---------+------+-----+---------+----------------+
| id       | int(10) | NO   | PRI | NULL    | auto_increment |
| clave_e  | int(8)  | NO   | MUL | NULL    |                |
| codigo_p | int(8)  | NO   | MUL | NULL    |                |
| cantidad | int(10) | NO   |     | NULL    |                |
+----------+---------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> 

Clase del 5 de mayo 2013:
quice85@quice85-laptop:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 172
Server version: 5.1.67-0ubuntu0.10.04.1 (Ubuntu)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+-----------------------+
| Database              |
+-----------------------+
| information_schema    |
| 6isc                  |
| NACION                |
| NACION_MEX            |
| alumnos               |
| banco_quice85         |
| banquice              |
| base_uni              |
| biblioteca            |
| biblioteca_x          |
| codeka                |
| cucs                  |
| cucslau               |
| datosemp              |
| isc5                  |
| iudm                  |
| iudm_isc              |
| mysql                 |
| phpmyadmin            |
| puntopascual          |
| puntoventa            |
| quice85               |
| siee                  |
| systemprog            |
| todo1000              |
| transito_tap          |
| universidad_soconusco |
| ventasiee             |
| ventaspio             |
+-----------------------+
29 rows in set (0.15 sec)

mysql> create database linux;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+-----------------------+
| Database              |
+-----------------------+
| information_schema    |
| 6isc                  |
| NACION                |
| NACION_MEX            |
| alumnos               |
| banco_quice85         |
| banquice              |
| base_uni              |
| biblioteca            |
| biblioteca_x          |
| codeka                |
| cucs                  |
| cucslau               |
| datosemp              |
| isc5                  |
| iudm                  |
| iudm_isc              |
| linux                 |
| mysql                 |
| phpmyadmin            |
| puntopascual          |
| puntoventa            |
| quice85               |
| siee                  |
| systemprog            |
| todo1000              |
| transito_tap          |
| universidad_soconusco |
| ventasiee             |
| ventaspio             |
+-----------------------+
30 rows in set (0.00 sec)

mysql> use linux;
Database changed
mysql> create table usuarios(clave int(8) not null,usuario varchar(35),correo varchar(40));
Query OK, 0 rows affected (0.08 sec)

mysql> describe usuarios;
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| clave   | int(8)      | NO   |     | NULL    |       |
| usuario | varchar(35) | YES  |     | NULL    |       |
| correo  | varchar(40) | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> alter table usuarios rename users;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
+-----------------+
| Tables_in_linux |
+-----------------+
| users           |
+-----------------+
1 row in set (0.00 sec)

mysql> describe users;
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| clave   | int(8)      | NO   |     | NULL    |       |
| usuario | varchar(35) | YES  |     | NULL    |       |
| correo  | varchar(40) | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> alter table users change usuario name varchar(40);
Query OK, 0 rows affected (0.12 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe users;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| clave  | int(8)      | NO   |     | NULL    |       |
| name   | varchar(40) | YES  |     | NULL    |       |
| correo | varchar(40) | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> alter table users drop correo;
Query OK, 0 rows affected (0.08 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe users;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| clave | int(8)      | NO   |     | NULL    |       |
| name  | varchar(40) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> alter table users add email varchar(50);
Query OK, 0 rows affected (0.08 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe users;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| clave | int(8)      | NO   |     | NULL    |       |
| name  | varchar(40) | YES  |     | NULL    |       |
| email | varchar(50) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> insert into users values(1001,"Rodrigo","rog12@outlook.com");
Query OK, 1 row affected (0.00 sec)

mysql> insert into users values(1003,"Karla","karlaV@outlook.com"),(2832,"Daniel","dani@outlook.com"),(2834,"Rosa","rosa@otulook.com");
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from users;
+-------+---------+--------------------+
| clave | name    | email              |
+-------+---------+--------------------+
|  1001 | Rodrigo | rog12@outlook.com  |
|  1003 | Karla   | karlaV@outlook.com |
|  2832 | Daniel  | dani@outlook.com   |
|  2834 | Rosa    | rosa@otulook.com   |
+-------+---------+--------------------+
4 rows in set (0.00 sec)

mysql> insert into users (clave,name) values (1002,"Marta"),(2734,"Rodrigo"),(77326,"Agusto");
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from users;
+-------+---------+--------------------+
| clave | name    | email              |
+-------+---------+--------------------+
|  1001 | Rodrigo | rog12@outlook.com  |
|  1003 | Karla   | karlaV@outlook.com |
|  2832 | Daniel  | dani@outlook.com   |
|  2834 | Rosa    | rosa@otulook.com   |
|  1002 | Marta   | NULL               |
|  2734 | Rodrigo | NULL               |
| 77326 | Agusto  | NULL               |
+-------+---------+--------------------+
7 rows in set (0.00 sec)

mysql> insert into users (name,clave) values ("Esteban",12673),("Sergio",434398),(8732,"Javier");
Query OK, 3 rows affected, 1 warning (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from users;
+--------+---------+--------------------+
| clave  | name    | email              |
+--------+---------+--------------------+
|   1001 | Rodrigo | rog12@outlook.com  |
|   1003 | Karla   | karlaV@outlook.com |
|   2832 | Daniel  | dani@outlook.com   |
|   2834 | Rosa    | rosa@otulook.com   |
|   1002 | Marta   | NULL               |
|   2734 | Rodrigo | NULL               |
|  77326 | Agusto  | NULL               |
|  12673 | Esteban | NULL               |
| 434398 | Sergio  | NULL               |
|      0 | 8732    | NULL               |
+--------+---------+--------------------+
10 rows in set (0.00 sec)

mysql> update users set clave=34880, name="Jaime" where name=8732;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from users;
+--------+---------+--------------------+
| clave  | name    | email              |
+--------+---------+--------------------+
|   1001 | Rodrigo | rog12@outlook.com  |
|   1003 | Karla   | karlaV@outlook.com |
|   2832 | Daniel  | dani@outlook.com   |
|   2834 | Rosa    | rosa@otulook.com   |
|   1002 | Marta   | NULL               |
|   2734 | Rodrigo | NULL               |
|  77326 | Agusto  | NULL               |
|  12673 | Esteban | NULL               |
| 434398 | Sergio  | NULL               |
|  34880 | Jaime   | NULL               |
+--------+---------+--------------------+
10 rows in set (0.00 sec)

mysql> delete from users where clave=12673;
Query OK, 1 row affected (0.00 sec)

mysql> select * from users;
+--------+---------+--------------------+
| clave  | name    | email              |
+--------+---------+--------------------+
|   1001 | Rodrigo | rog12@outlook.com  |
|   1003 | Karla   | karlaV@outlook.com |
|   2832 | Daniel  | dani@outlook.com   |
|   2834 | Rosa    | rosa@otulook.com   |
|   1002 | Marta   | NULL               |
|   2734 | Rodrigo | NULL               |
|  77326 | Agusto  | NULL               |
| 434398 | Sergio  | NULL               |
|  34880 | Jaime   | NULL               |
+--------+---------+--------------------+
9 rows in set (0.00 sec)





Clase del 9 de junio:--------------------------------
mysql> create database transito_tap;
Query OK, 1 row affected (0.00 sec)

mysql> use transito_tap;
Database changed
mysql> create table automoviles(placa varchar(7)primary key,modelo varchar(30)not null,color varchar(15) default "Blanco");
Query OK, 0 rows affected (0.15 sec)

mysql> describe automoviles;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| placa  | varchar(7)  | NO   | PRI | NULL    |       |
| modelo | varchar(30) | NO   |     | NULL    |       |
| color  | varchar(15) | YES  |     | Blanco  |       |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> create table tarjetas_circulacion(n_serie int(21)primary key,propietario varchar(45)not null, tipo varchar(15));
Query OK, 0 rows affected (0.08 sec)

mysql> describe tarjetas_circulacion;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| n_serie     | int(21)     | NO   | PRI | NULL    |       |
| propietario | varchar(45) | NO   |     | NULL    |       |
| tipo        | varchar(15) | YES  |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql> create table registros(placa_r varchar(7) unique,n_serie_r int(21) unique,fecha date,foreign key(placa_r)references automoviles(placa),foreign key (n_serie_r)references tarjetas_circulacion(n_serie));
Query OK, 0 rows affected (0.06 sec)

mysql> describe registros;
+-----------+------------+------+-----+---------+-------+
| Field     | Type       | Null | Key | Default | Extra |
+-----------+------------+------+-----+---------+-------+
| placa_r   | varchar(7) | YES  | UNI | NULL    |       |
| n_serie_r | int(21)    | YES  | UNI | NULL    |       |
| fecha     | date       | YES  |     | NULL    |       |
+-----------+------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> show tables;
+------------------------+
| Tables_in_transito_tap |
+------------------------+
| automoviles            |
| registros              |
| tarjetas_circulacion   |
+------------------------+
3 rows in set (0.00 sec)

mysql> describe automoviles;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| placa  | varchar(7)  | NO   | PRI | NULL    |       |
| modelo | varchar(30) | NO   |     | NULL    |       |
| color  | varchar(15) | YES  |     | Blanco  |       |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> describe tarjetas_circulacion;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| n_serie     | int(21)     | NO   | PRI | NULL    |       |
| propietario | varchar(45) | NO   |     | NULL    |       |
| tipo        | varchar(15) | YES  |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> 

mysql> 

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s