A
A
Anton-Pluton2018-04-17 21:22:03
PHP
Anton-Pluton, 2018-04-17 21:22:03

Why is the data not being written to the database??

Here is the code where the user writes data

<li><p align="right"><label id="label-name">Имя<span>*</span></label><input maxlength="15" type="text" id="name_review" /></p></li>
      <li><p align="right"><label id="label-good">Достоинства<span>*</span></label><textarea id="good_review"></textarea></p></li >
      <li><p align="right"><label id="label-bad">Недостатки<span>*</span></label><textarea id="bad_review"></textarea></p></li>
      <li><p align="right"><label id="label-comment">Комментарий</label><textarea id="comment_review"></textarea></p></li>

      <p id="reload-img"><img src="../ring.gif" /></p> <p id="button-send-review" iid="'.$post_id.'">Отправить</p>

Here is the code that sends this data to the database
if($_SERVER["REQUEST_METHOD"] == "POST"){

  include("connect_db.php");

  $id = clear_string($_POST['id']);
  $name = iconv ("UTF-8", "cp1251" , clear_string($_POST['name']));
  $good = iconv ("UTF-8", "cp1251" , clear_string($_POST['good']));
  $bad = iconv ("UTF-8", "cp1251" , clear_string($_POST['bad']));
  $comment = iconv ("UTF-8", "cp1251" , clear_string($_POST['comment']));

    mysqli_query ($connection,"INSERT INTO table_reviews(products_id,name,good_reviews,bad_reviews,comment,date)
            VALUES(
                '".$id."',
                '".$name."',
                '".$good."',
                '".$bad."',
                '".$comment."',
                  NOW()
                )");

echo 'yes';

}

Please help me find the error in the code. The data is not sent to the database. Thank you very much in advance !

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad Nevlad, 2018-04-18
@Anton-Pluton

Field parameters in the form (I hope you have it wrapped in the form?) are passed by name and not by id. It's true that you and the id in the fields do not match what you get in $_POST.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question