Modificar campos con la sentencia UPDATE
Publicado por Alvaro (6 intervenciones) el 02/01/2019 08:50:58
Hola... no logro modificar los campos con la sentencia SQL UPDATE, me da error... Posibles causas?
He adjuntado 3 paginas creadas para que veáis el procedimiento que he seguido !!!
He adjuntado 3 paginas creadas para que veáis el procedimiento que he seguido !!!
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
186
187
// Pagina 1
<?php
$conexion= mysqli_connect("localhost: 3306", "root", "", "taxicorp")or die("Error en la conexion con la BD");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Modificar datos</title>
<style>
@font-face{
font-family: 'RobotoMono';
src: url(Tipografias/RobotoMono.ttf);
font-style: normal;
}
table{
width: 765px; height: 20px;
border: ridge thick aliceblue;
background-color: antiquewhite;
table-layout: inherit;
}
#estatic{
position: absolute;
left: 185px; top: 85px;
}
</style>
</head>
<body bgcolor="#000000">
<div id="estatic">
<form action="mod_dat_tax2.php" method="post">
<table border="1">
<tr>
<td><b>*</b></td>
<td><b>Matricula</b></td>
<td><b>Modelo</b></td>
<td><b>Conductor</b></td>
</tr>
<?php
$sel= "SELECT * FROM taxis";
$exec= mysqli_query($conexion, $sel);
while($datos= mysqli_fetch_array($exec)){
?>
<tr>
<td><input type="radio" name="taxi_radio" value="<?php echo($datos['Matricula']);?>"></td>
<td><?php echo($datos['Matricula']);?></td>
<td><?php echo($datos['Modelo']);?></td>
<td><?php echo($datos['Nombre']." ".$datos['Apellidos']);?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center">
<input type="submit" name="botonEnviar" value="Modificar Datos"></td>
</tr>
</table>
</form>
<a href="contenido.php" style="float: right; font: 14px bold RobotoMono; color: aliceblue">Volver</a>
</div>
</body>
</html>
// Pagina 2
<?php
$conexion= mysqli_connect("localhost: 3306", "root", "", "taxicorp");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Modificar datos</title>
</head>
<style>
@font-face{
font-family: 'RobotoMono';
src: url(Tipografias/RobotoMono.ttf);
font-style: normal;
}
table{
width: 765px; height: 20px;
border: ridge thick aliceblue;
background-color: antiquewhite;
table-layout: inherit;
}
#estatic{
position: absolute;
left: 185px; top: 85px;
}
h3{
color: aliceblue;
}
</style>
<?php
$sql="SELECT * FROM taxis WHERE Matricula='".$_POST['taxi_radio']."'";
$exec= mysqli_query($conexion, $sql);
$registro= mysqli_fetch_array($exec);
?>
<body bgcolor="#000000">
<div id="estatic">
<form action="res_mod_tax.php" method="post">
<table border="1">
<tr>
<td colspan="2" align="center"><b>Matricula: <font color="#BB0B0E">
<?php echo($_POST['taxi_radio']);?></font></b></td>
</tr>
<tr>
<td><b>Modelo:</b></td>
<td><input type="text" name="Modelo" size="40" value="<?php echo($registro['Modelo']);?>"></td>
</tr>
<tr>
<td><b>Nombre y Apellidos:</b></td>
<td>
<input type="text" name="Nombre" value="<?php echo($registro['Nombre']);?>">
<br>
<input type="text" name="Apellidos" maxlength="35" value="<?php echo($registro['Apellidos']);?>"></td>
</tr>
<tr>
<td><b>Libre:</b></td>
<td><input type="checkbox" name="libre"
<?php if($registro["Ocupado"])
echo("checked");?>></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="botonenviar" value="Modificar Datos"></td>
</tr>
</table>
</form>
<a href="mod_dat_tax.php" style="float: right; font: 14px bold RobotoMono; color: aliceblue">Volver</a>
</div>
</body>
</html>
// Pagina 3
<?php
$conexion= mysqli_connect("localhost: 3306", "root", "", "taxicorp");
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Documento sin título</title>
</head>
<body>
<?php
$cambia ="UPDATE taxis SET Modelo='".$_POST['Modelo']."',"."Nombre='".$_POST['Nombre']."',";
$cambia.="Apellidos='".$_POST['Apellidos']."',Ocupado=";
if (isset($_POST["Libre"]))
$cambia.="true";
else
$cambia.="false";
$cambia.=" WHERE Matricula='".$_POST['taxi_radio']."'";
// Sentencia SQL
$exec= mysqli_query($conexion, $cambia);
echo($cambia."<br>");
// Registro en la tabla taxis
if($exec)
echo("<h3><center>Datos Modificados!!</center></h3>");
else
echo("<h3><center>Error!!</center></h3>");
?>
<br>
<a href="mod_dat_tax.php" style="float: right; font: 14px bold RobotoMono; color: aliceblue">Volver</a>
</body>
</html>
- 2019-01-02-2.rar(17,4 KB)
Valora esta pregunta
0