【发布时间】:2021-12-20 12:01:39
【问题描述】:
我正在尝试更新我的数据库中的一张表。为了确定我要更新的行,我使用我在表单中输入的电子邮件作为搜索的基础,然后请求我输入要更新的其余数据。问题是执行操作后它会抛出一个错误,我一直无法找到我的错误。在这个网站上我使用:
我请求数据的页面。
一个 PHP 连接。
处理更新的 PHP。
数据库。
接下来我将说明过程,我将有一个代码sn -p
我请求和输入数据的屏幕。
表单代码
<label>Localidad</label>
<input type="text" name="labelLocalidad1" required/>
</div>
<div class="form-element">
<label>Direccion</label>
<input type="text" name="labelDireccion1" required/>
</div>
<div class="form-element">
<label>Codigo Postal</label>
<input type="text" name="labelPostal1" pattern="[a-zA-Z0-9]+" required/>
</div>
<div class="form-element">
<label>Providencia</label>
<input type="text" name="labelProvidencia1" pattern="[a-zA-Z0-9]+" required/>
</div>
<div class="form-element">
<label>Numero de telefono</label>
<input type="number" name="labeltelefono1" pattern="[a-zA-Z0-9]+" required/>
</div>
<button type="submit" name="PAGO" value="PAGO">Registrar direccion</button>
</form>
连接代码
<?php
$host = "localhost";
$user = "root";
$clave = "";
$bd = "usuarios";
$conectar = mysqli_connect($host,$user,$clave,$bd);
?>
php
<?php
require 'conexion.php';
$idusuario= session_id();
$localidad = $_POST['labelLocalidad1'];
$direccion = $_POST['labelDireccion1'];
$postal = $_POST['labelPostal1'];
$providencia = $_POST['labelProvidencia1'];
$telefono = $_POST['labeltelefono1'];
$correoentrega = $_POST['labelcorreo1'];
$actualizar =("UPDATE datosentrega set localidad='$localidad',direccion='$direccion',postal=$postal,providencia='$providencia',telefono='$telefono' WHERE correoentrega='$correoentrega'");
$query = mysqli_query($conectar,$actualizar);
if($query){
echo "<script> alert('Datos registrados');
</script>";
}else{
echo "<script> alert('Error favor de revisar el codigo XD');
</script>";
}
【问题讨论】:
-
错误是什么?请查阅 PHP 中的 SQL 注入预防。
-
警告:您对SQL Injections 持开放态度,应该使用参数化的prepared statements,而不是手动构建查询。它们由PDO 或MySQLi 提供。永远不要相信任何形式的输入!即使您的查询仅由受信任的用户执行,you are still in risk of corrupting your data。 Escaping is not enough!