-
Notifications
You must be signed in to change notification settings - Fork 1
/
vale.php
185 lines (150 loc) · 5.34 KB
/
vale.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Vale</title>
</head>
</html>
<?php
function mostrarForm() {
echo '<html>
<form id="formulario" method="POST" action="vale.php">
<label><h3>Vale</h3></label><br>
<input type="hidden" name="idfunc" id="idfunc" />
<input type="hidden" name="idvale" id="idvale" /><br>
<label>Funcionario</label><br>
<select name="nome">
<option>Selecione...</option>
</html>';
mostrarSelectTag();
echo '<html>
</select>
<br>
<label>Data</label><br>
<input type="date" name="data" id="data" size=10/> <br>
<label>Valor</label><br>
<input type="text" name="valor" id="valor" size=30 />
<br><br>
<input type="submit" name="submit"/>
<br>
</form>
</html>';
}
///////////CONEXÃO COM BANCO///////////////////////
$server = "localhost";
$usuario = "root";
$pass = "";
$banco = "studiomaisvoce";
$conexao = mysql_connect($server, $usuario, $pass, $banco) or die (mysql_error());
mysql_select_db($banco) or die(mysql_error());
/////////////MOSTRA TABELA COM INSERÇÕES//////////////
function mostrarSelectTag(){
$server = "localhost";
$usuario = "root";
$pass = "";
$banco = "studiomaisvoce";
$conexao = mysql_connect($server, $usuario, $pass, $banco) or die (mysql_error());
mysql_select_db($banco) or die(mysql_error());
$sql=mysql_query("SELECT Id_Func, Nm_Func FROM funcionario");
$myData=$sql;
while($record = mysql_fetch_array($myData)){
echo "<form action=vale.php method=post>";
echo "<option>" . $record['Nm_Func'] . "</option>";
echo "</form>";
}
}
//MOSTRA FORM HTML
mostrarForm();
/////////////INSERE//////////////
if (isset($_POST['submit'])&&($_POST['valor'])){
$datavale=$_POST['data'];
$valor=$_POST['valor'];
$nome=$_POST['nome'];
$id=mysql_query("SELECT Id_Func FROM funcionario WHERE Nm_Func='$nome'");
//fetch_row senão não retornava o id
$idresult = mysql_fetch_row($id);
$idfuncionario = $idresult[0];
//echo "$idfuncionario";
$sql=mysql_query("INSERT INTO vale (Id_Funcionario, Dt_Vale, Vl_Vale)VALUES('$idfuncionario', '$datavale', '$valor')");
mostrarTabela();
}
/////////////MOSTRA TABELA COM INSERÇÕES//////////////
function mostrarTabela(){
$sql=mysql_query("SELECT funcionario.Nm_Func, vale.Id_Vale, vale.Dt_Vale, vale.Vl_Vale, vale.Id_Funcionario FROM funcionario, vale WHERE funcionario.Id_Func=vale.Id_Funcionario");
$myData=$sql;
echo "<table border = 1>
<tr>
<th>Nº Vale</th>
<th>Nome do funcionario</th>
<th>Data</th>
<th>Valor</th>
</tr>";
while($record = mysql_fetch_array($myData)){
echo "<form action=vale.php method=post>";
echo "<tr>";
echo "<td>" . $record['Id_Vale'] . "</td>";
echo "<td>" . $record['Nm_Func'] . " </td>";
echo "<td>" . $record['Dt_Vale'] . " </td>";
echo "<td>" . $record['Vl_Vale'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['Id_Vale'] . "</td>";
echo "<td>" . "<input type=submit name=alterar1 value=alterar" . " </td>";
echo "<td>" . "<input type=submit name=deletar value=deletar" . " </td>";
echo "</tr>";
echo "</form>";
}
echo "</table>";
}
/////////////DELETA//////////////
if (isset ($_POST['deletar'])){
$sqlDelete=("DELETE from vale WHERE Id_Vale='$_POST[hidden]'");
mysql_query($sqlDelete,$conexao);
//$myData or die(mysql_error());
//$myData->execute();
//echo "deletado!!";
mostrarTabela();
}
/////////////ALTERA1//////////////
if (isset ($_POST['alterar1'])){
$sql=mysql_query("SELECT funcionario.Nm_Func, vale.Id_Vale, vale.Dt_Vale, vale.Vl_Vale, vale.Id_Funcionario FROM funcionario, vale WHERE vale.Id_Vale='$_POST[hidden]' AND funcionario.Id_Func=vale.Id_Funcionario");
$myData=$sql;
while($record = mysql_fetch_array($myData)){
echo "<form method=POST action=vale.php>";
echo "<table border = 1>
<tr>
<th>Nº Vale</th>
<th>Nome do funcionario</th>
<th>Data</th>
<th>Valor</th>
</tr>";
echo "<tr>";
echo "<td>" . $record['Id_Vale'] . " </td>";
echo "<td>" . $record['Nm_Func'] . " </td>";
//echo "<td>" . "<select name=nome>" . "<option>" . mostrarSelectTag() . "</option>" . "</select>" . " </td>";
echo "<td>" . "<input type=text name=data value=". $record['Dt_Vale'] . " </td>";
echo "<td>" . "<input type=text name=valor value=". $record['Vl_Vale'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['Id_Vale'] . " </td>";
echo "<td>" . "<input type=submit name=alterar2 value=alterar" . " </td>";
echo "<td>" . "<input type=button value=cancelar onClick=history.go(-1)" . " </td>";
echo "</tr>";
echo "</form>";
echo "</table>";
}
}
/////////////ALTERA2//////////////
if (isset ($_POST['alterar2'])){
$sqlUpdate=("UPDATE vale SET Dt_Vale='$_POST[data]', Vl_Vale='$_POST[valor]' WHERE Id_Vale='$_POST[hidden]'");
mysql_query($sqlUpdate, $conexao);
//$myData or die(mysql_error());
//echo "modificado!";
mostrarTabela();
mysql_close($conexao);
}
/*<select name="funcionario">
<option value="func1">Maria</option>
<option value="func2">Jose</option>
<option value="func3">Lia</option>
<option value="func4">Joana</option>
</select><br>
<input type="text" name="funcionario" id="funcionario" size=50 /> <br>
*/
?>