forked from obetancourthunicah/IF412NegociosWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathej7.php
89 lines (79 loc) · 2.17 KB
/
ej7.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/*
CREATE TABLE `categorias` (
`ctgid` BIGINT(8) NOT NULL AUTO_INCREMENT,
`ctgdsc` VARCHAR(45) NULL,
`ctgest` CHAR(3) NULL,
PRIMARY KEY (`ctgid`));
*/
$txtDsc = "";
$cmbEst = "ACT";
$last = "";
$conn = new mysqli("127.0.0.1","root",
"root","nw201501");
if($conn->errno){
die($conn->error);
}
if(isset($_POST["btnSave"])){
$txtDsc = $_POST["txtDsc"];
$cmbEst = $_POST["cmbEst"];
$insertSQL = "Insert into categorias (ctgdsc, ctgest) ";
$insertSQL .= "value ('".$txtDsc."','".$cmbEst."');";
$inserted = $conn->query($insertSQL);
$last = $conn->insert_id;
}
$str = "SELECT * from categorias;";
$cursor = $conn->query($str);
$categorias = array();
while($registro = $cursor->fetch_assoc()){
//obtenga el registro de forma associativa
/* $registro = array(
"ctgid"=> 1,
"ctgdsc"=> "Algun Valor",
"ctgest"=> "ACT"
);
*/
$categorias[]=$registro;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Ejemplo 2 de Acceso a Datos en MYSQL</title>
</head>
<body>
<h1>Categorías</h1>
<form action="ej7.php" method="post">
<label for="txtDsc">Categoría</label>
<input type="text" name="txtDsc"
id="txtDsc" value="<?php echo $txtDsc; ?>"/>
<br/>
<label for="cmbEst">Estado</label>
<select name="cmbEst" id="cmbEst">
<option value="ACT"
<?php echo $cmbEst == "ACT"?"selected":""; ?>
>Activo</option>
<option value="INA"
<?php echo $cmbEst == "INA"?"selected":""; ?>
>Inactivo</option>
</select>
</br>
<input type="submit" name="btnSave" id="btnSave" value="Guardar" />
</form>
<hr/>
<h2>Categorías</h2>
<table border="1">
<tr>
<th>Código</th><th>Categoría</th><th>Estado</th></tr>
<?php
foreach($categorias as $categoria){
echo "<tr><td>".$categoria["ctgid"]."</td>";
echo "<td>".$categoria["ctgdsc"]."</td>";
echo "<td>".$categoria["ctgest"]."</td></tr>";
}
?>
</table>
<?php echo "Last Saved Id = $last"?>
</body>
</html>