forked from obetancourthunicah/IF412NegociosWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproveedores.php
164 lines (154 loc) · 5.27 KB
/
proveedores.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
//Alumno: Jonathan Oliva
$registros = array();
$txtCodigo=0;
$txtDescripcion="";
$txtEmail="";
$txtTel="";
$txtCont="";
$txtDir="";
$txtEstado="";
$conn = new mysqli("127.0.0.1", "root", "studentpwd", "nw201501");
if($conn->errno){
die("DB no can: " . $conn->error);
}
if(isset($_POST["btnIns"])){
$txtCodigo = 0;
$txtDescripcion = $_POST["txtDsc"];
$txtEmail = $_POST["txtEmail"];
$txtTel = $_POST["txtTel"];
$txtCont = $_POST["txtCont"];
$txtDir = $_POST["txtDir"];
$txtEstado = $_POST["txtSts"];
$sqlstr = "INSERT INTO `nw201501`.`proveedores` ( `prvdsc`, `prvemail`, `prvtel`, `prvcont`, `prvdir`, `prvest`)";
$sqlstr .= "VALUES ( '". $txtDescripcion ." ' , '" . $txtEmail . "', '". $txtTel ."', '" . $txtCont . "', '". $txtDir ."', '" . $txtEstado . "');";
$result = $conn->query($sqlstr);
}
if(isset($_POST["btnAct"])){
$txtCodigo = intval($_POST["txtCod"]);
$txtDescripcion = $_POST["txtDsc"];
$txtEmail = $_POST["txtEmail"];
$txtTel = $_POST["txtTel"];
$txtCont = $_POST["txtCont"];
$txtDir = $_POST["txtDir"];
$txtEstado = $_POST["txtSts"];
$sqlstr="UPDATE `nw201501`.`proveedores` SET ";
$intComa=0;
if((!is_null($txtCodigo)) && $txtCodigo!=0){
if((!is_null($txtDescripcion)) && $txtDescripcion!=""){
$sqlstr.="`prvdsc` = '".$txtDescripcion."'";
$intComa=1;
}
if((!is_null($txtEmail)) && $txtEmail!=""){
if($intComa==1){
$sqlstr.=",`prvemail` = '".$txtEmail."'";
}else{
$sqlstr.="`prvemail` = '".$txtEmail."'";
}
$intComa=1;
}
if((!is_null($txtTel)) && $txtTel!=""){
if($intComa==1){
$sqlstr.=",`prvtel` = '".$txtTel."'";
}else{
$sqlstr.="`prvtel` = '".$txtTel."'";
}
$intComa=1;
}
if((!is_null($txtCont)) && $txtCont!=""){
if($intComa==1){
$sqlstr.=",`prvcont` = '".$txtCont."'";
}else{
$sqlstr.="`prvcont` = '".$txtCont."'";
}
$intComa=1;
}
if((!is_null($txtDir)) && $txtDir!=""){
if($intComa==1){
$sqlstr.=",`prvdir` = '".$txtDir."'";
}else{
$sqlstr.="`prvdir` = '".$txtDir."'";
}
$intComa=1;
}
if($intComa==1){
$sqlstr.=",`prvest` = '".$txtEstado."'";
}else{
$sqlstr.="`prvest` = '".$txtEstado."'";
}
$sqlstr.=" WHERE `prvid` = ".$txtCodigo.";";
$result = $conn->query($sqlstr);
}
}
$sqlQuery = "Select * from `nw201501`.`proveedores`;";
$resulCursor = $conn->query($sqlQuery);
while($registro = $resulCursor->fetch_assoc()){
$registros[] = $registro;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Formulario proveedores</title>
</head>
<body>
<h1>Proveedores</h1>
<form action="proveedores.php" method="POST">
<label for="txtCod">Codigo</label>
<input type="text" name="txtCod" id="txtCod" value="<?php echo $txtCodigo;?>"/>
<br/>
<label for="txtDsc">Descripción</label>
<input type="text" name="txtDsc" id="txtDsc" value="<?php echo $txtDescripcion;?>"/>
<br/>
<label for="txtEmail">Email</label>
<input type="email" name="txtEmail" id="txtEmail" value="<?php echo $txtEmail;?>"/>
<br/>
<label for="txtTel">Telefono</label>
<input type="text" name="txtTel" id="txtTel" value="<?php echo $txtTel;?>"/>
<br/>
<label for="txtCont">Contacto</label>
<input type="text" name="txtCont" id="txtCont" value="<?php echo $txtCont;?>"/>
<br/>
<label for="txtDir">Direccion</label>
<input type="text" name="txtDir" id="txtDir" value="<?php echo $txtDir;?>"/>
<br/>
<label for="txtSts">Estado</label>
<select name="txtSts" id="txtSts">
<option value="PND" <?php echo $txtEstado=="PND"?"selected":"";?>>Pendiente</option>
<option value="CNF" <?php echo $txtEstado=="CNF"?"selected":"";?>>Confirmado</option>
<option value="CNL" <?php echo $txtEstado=="CNL"?"selected":"";?>>Cancelado</option>
</select>
<br/>
<input type="submit" name="btnIns" value="Ingresar" />
<input type="submit" name="btnAct" value="Actualizar" />
</form>
<div>
<h2>Datos</h2>
<table>
<tr>
<th>Codigo</th>
<th>Descripción</th>
<th>Email</th>
<th>Telefono</th>
<th>Contacto</th>
<th>Direccion</th>
<th>Estado</th>
</tr>
<?php
if(count($registros) > 0){
foreach($registros as $registro){
echo "<tr><td>".$registro["prvid"]."</td>";
echo "<td>".$registro["prvdsc"]."</td>";
echo "<td>".$registro["prvemail"]."</td>";
echo "<td>".$registro["prvtel"]."</td>";
echo "<td>".$registro["prvcont"]."</td>";
echo "<td>".$registro["prvdir"]."</td>";
echo "<td>".$registro["prvest"]."</td></tr>";
}
}
?>
</table>
</div>
</body>
</html>