The form:

<?php // файл: edit_php.php if(isset($_GET['id'])){ $id = $_GET['id']; $result = mysql_query("SELECT * FROM php WHERE id=$id",$db); $myrow = mysql_fetch_array($result); printf(' <h1>Редагування статті <i><u>%s</u></i></h1> <div class="edit_article"> <form action="edit.php" method="post"> <p>Назва:<br><input class="php_name" type="text" name="name" value="%s"></p> <p><textarea name="text">%s</textarea></p> <p>Опис(для статті):<br><textarea name="description">%s</textarea></p> <center><h3>SEO-налаштування</h3></center> <p>Опис:<br><textarea>%s</textarea></p> <p>Ключові слова(через кому):<br><input class="php_name" name="meta_k" value="%s"></p> <input name="id" type="hidden" value="%s"> <p><input class="submit" type="submit" name="submit_php" value="Змінити"></p> </form> </div>',$myrow['name'],$myrow['name'],$myrow['text'],$myrow['description'],$myrow['meta_d'],$myrow['meta_k'],$id); } 

Handler:

 <?php // файл edit.php: include('../../db.php'); if(isset($_POST['submit_php'])){ $id = $_POST['id']; $name = $_POST['name']; $text = $_POST['text']; $description = $_POST['description']; $meta_d = $_POST['meta_d']; $meta_k = $_POST['meta_k']; $query = mysql_query("UPDATE `php` SET `name`='$name', `text`='$text', `description`='$description', `meta_d`='$meta_d', `meta_k`='$meta_k'"); } 

Why data is not inserted into MySQL?


enter image description here

Here there are such fields !!! And it writes INTO not

  • one
    Which mistakes? Is $_POST['submit_php'] ? And finally forget about mysql_query , use mysqli :: query or PDO - korytoff
  • and you have not forgotten in the update that a thread of type where id = $ id? - splash58
  • Before you use the request in the code, you can check it by doing it directly, if the request works correctly, then you can see what comes in the post, and what the final request is, look - Bookin
  • All post is well sent and from what is with the request - Oleksiy Gavrishkiv
  • Provide the output of the mysql_error () function, the query you have made is incorrect, there is no concatenation of strings, he most likely does not understand what you are sending for heresy to him in the record, go further where the word WHERE is, he does not understand what to edit. And check that you have variables of type $ _POST. - LevBazdyrev

1 answer 1

$ query = mysql_query ("UPDATE php SET name = '". $ name. "', text = '". $ text. "', description = '". $ description. "', meta_d = '". $ meta_d. "', meta_k ='". $ meta_k. "'"); - this is how it should work ... you do not have variables inside the string ... well, you probably need to update a specific line - add the row identifier ... best, open the query and try to execute it via myadmin

  • does not work. Maybe UTB from textarea - Oleksiy Gavrishkiv
  • $ query = mysql_query ("UPDATE php SET name = '". $ name. "', text = '". $ text. "', description = '". $ description. "', meta_d = '". $ meta_d. "', meta_k ='". $ meta_k. "'WHERE id ='". $ id. "'"); No, there is no explicit indication of what exactly to change ... Insert some identifier into the request as in the condition where ... - Run Pobedy
  • That where I added "UPDATE php SET name = '". $ Name. "', Text = '". $ Text. "', Description = '". $ Description. "', Meta_d = '". $ Meta_d. " ', meta_k =' ". $ meta_k." '. WHERE id =' ". $ id." '" - Oleksiy Gavrishkiv
  • echo "UPDATE php SET name = '". $ name. "', text = '". $ text. "', description = '". $ description. "', meta_d = '". $ meta_d. "', meta_k = '". $ meta_k."' WHERE id = '". $ id."' "; What is displayed on the screen? - Boris Runs
  • UPDATE php SET name = 'Lesson1. Enter ', text =' then text from form then ', description =' then text and then already ', meta_d =' ', meta_k =' PHP dfghgfrdfgfd edrfg 'WHERE id =' 1 ' - Oleksiy Gavrishkiv