I wonder if it is possible to send data from a form on the same page with all the code. Separately it works perfectly for me, but what I need is for the data to be sent in the same file and refreshed.
I leave my code here.
<?php
//Recojo datos del formulario
$id = $_POST['intro'];
$dato = $_POST['datonuevo'];
//Consulta para actualizar los datos
$sql1 = "UPDATE dimension_intro SET text_work='$dato' WHERE id = '$id'";
if ($conn->query($sql1) === TRUE) {
echo "Actualizacion realizada con exito";
} else {
echo "Error al actualizar: " . $conn->error;
}
$datosantiguos="SELECT id, text_work FROM dimension_intro ORDER BY id";//consulta datos antiguos
$result=mysqli_query($conn, $datosantiguos);//ejecuto la consulta
?>
<select name="intro">
<?php
//recorro los datos antiguos
while ($row=mysqli_fetch_array($result))
{
echo '<option value="'.$row["id"].'">'.$row["text_work"].'</option>';
}
?>
</select>
<br>Nueva intro<br>
<input type="text" name="datonuevo"> <br>
<input type="submit" value="Actualizar" ><br> <!-- Aqui tenias mal escrito submit jaja -->
</form>
<?php
$conn->close();
?>