0
sqlテーブルをhtml形式で更新したいと思います。私は、ドロップダウンリストで要素を選択し、後でフォームで値を更新したいと思います。フォームを使用してMysqlを更新する
ここに私のコードは、ドロップダウンリストとフォームが動作しますが、私は選択した要素を取得するPHPコードを作る方法を知らなかった。
HTMLフォーム:
<?php
require("conectarBD.php");
$select = "SELECT id_serie, nombre FROM series";
$result = $conectar->query($select);
?>
Selecciona la serie que quieres modificar:
<br>
<select>
<?php
while ($row = $result->fetch_array())
{
?>
<option value=" <?php echo $row['id_serie'] ?> " >
<?php echo $row['nombre']; ?>
</option>
<?php
}
?>
</select>
<form action="modificar_serie.php" method="post">
<p>
Introduce los cambios a realizar:
</p>
<p>
<label for="textfield">Nombre</label>
<input type="text" name="nom" id="nom" />
<label for="textarea"></label>
</p>
<p>
<label for="textfield">Temporadas</label>
<input type="number" name="temp" id="temp" />
<label for="textarea"></label>
</p>
<p>
<label for="textfield"> Año de estreno</label>
<input type="text" name="est" id="est" />
<label for="textarea"></label>
</p>
<input type="Submit" value="Actualizar">
</form>
はPHP:
<?php
require("conectarBD.php");
$nombre = $_POST["nombre"];
$temp = $_POST["temp"];
$est = $_POST["est"];
$query="UPDATE series SET nombre = '.$nombre.', temporadas = '.$temp.', estreno= '.$est.' WHERE nombre='$nombre'";
mysqli_query($conectar,$query);
if(mysqli_affected_rows()>=0){
echo "<p>($nombre) Datos Actualizados<p>";
}else{
echo "<p>($nombre) No se ha podido actualizar en estos momentos<p>";
}
header("Location: ../index.php");
?>
これはあなたの質問には答えませんが、SQLインジェクションには気づきます。 [Here](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php#60496)は、アプリケーションのセキュリティを確保するのに役立つ良い記事です。 – mnme