Я делаю приложение с рецептами, и у меня проблемы с обновлением метода рецепта. У меня есть форма обновления и запрос SQL. Я даже проверил, являются ли входные переменные формы name
, description
и url
в моем операторе if
обновленными значениями. Они такие .. и мой SQL действителен. Тем не менее, когда я заполняю форму редактирования и нажимаю «Отправить», я возвращаюсь к странице со списком рецептов, причем рецепт, который я редактировал, не изменился.
Вот мой код.
<?php
$recipe_id = $_GET['recipe_id'];
$recipes_fetch_existing_row_query = mysqli_query($con, "SELECT * FROM recipes WHERE id='$recipe_id'");
$recipe = mysqli_fetch_array($recipes_fetch_existing_row_query);
$name = $recipe['name'];
$description = $recipe['description'];
$url = $recipe['url'];
if(isset($_POST['update_recipe'])) {
$name = $_POST['recipe_name'];
$description= $_POST['recipe_description'];
$url = $_POST['recipe_url'];
$recipe_update_query = mysqli_query($con, "UPDATE recipe SET name='$name', description='$description', url='$url' WHERE id='$recipe_id'");
header("Location: ../../../index.php");
}
?>
<form action="../../../index.php" class="update_recipe_form" method="POST">
<input type="text" name="recipe_name" placeholder="name" value="<?php echo $recipe_name ?>" required>
<textarea name="recipe_description" id="recipe_description" placeholder="Enter a brief description of the recipe"><?php echo $recipe_description; ?></textarea>
<input type="text" name="recipe_url" id="recipe_url" value="<?php echo $recipe_url ?>" placeholder="url" required>
<input type="submit" name="update_recipe" id="update_recipe" value="Update">
</form>
Any ideas? :(