我在PHP中使用表单来选择我想要更改的值,并选择将成为新值的值。 SQL查询成功运行,但更新不会发生。
index.php 的表单部分:
<form action="filmpontozas.php" method="POST">
<select name="cim">
<option disabled selected value> -- Válassz egy filmet! -- </option>
<?php
$sql = "SELECT cim FROM film";
$res = mysqli_query($conn, $sql) or die ('Hibás utasítás: '.mysqli_error($conn));
while ( ($current_row = mysqli_fetch_assoc($res))!= null) {
$cim = $current_row["cim"];
echo '<option value="'.$cim.'">'.$cim.'</option>';
}
echo '</select><select name="filmAZ">';
echo '<option disabled selected value> -- Válassz egy pontszámot! -- </option>';
$sql = "SELECT filmAZ, pontszam FROM film";
$res = mysqli_query($conn, $sql) or die ('Hibás utasítás: '.mysqli_error($conn));
while ( ($current_row = mysqli_fetch_assoc($res))!= null) {
echo '<option value="'.$current_row["filmAZ"].'">'.$current_row["pontszam"].'</option>';
}
?>
</select>
<input type="submit" name="update" value="Értékel!">
</form>
filmpontozas.php
<?php
$cim = $_POST["cim"];
$filmAZ = $_POST["filmAZ"];
$conn = mysqli_connect('localhost', 'root','') or die(mysqli_error($conn));
mysqli_select_db($conn, 'magyarimdb') or die(mysqli_error($conn));
$sql = 'UPDATE film SET filmAZ = '.$filmAZ." WHERE cim = '".$cim."'";
mysqli_query($conn, $sql) or die (mysqli_error($conn));
header("Location: koszonjuk.html");
?>
答案 0 :(得分:2)
更新您的MySQLi查询,如下所示:
$query = $this->mysqli->prepare("UPDATE film SET filmAZ=? WHERE cim=?");
// Check whether the prepare() succeeded
if ($query === false) {
trigger_error($this->mysqli->error, E_USER_ERROR);
return;
}
$query->bind_param('si', $filmAZ, $cim);
$status = $query->execute();
// Check whether the execute() succeeded
if ($status === false) {
trigger_error($query->error, E_USER_ERROR);
}