Y
Y
Yevhenii K2015-11-16 21:57:07
PHP
Yevhenii K, 2015-11-16 21:57:07

Why is it not adding data to the database?

Good evening! Help me please. There is a form that sends data to a file via POST, where they get into the property of the object, after which a request is executed that should add them. But it doesn't add anything. Post with data, the object takes the desired properties but does not work. A couple of days ago everything worked, other similar schemes work.
The form

<div class=com_block><div class=addcom>
  <form method=POST action=php/scripts/add_coment.php>
  <input type=text name=comment>
  <input type=text hidden=hidden name=login value={$_SESSION['login']}>
  <input type=text hidden=hidden name=user_id value={$_SESSION['user_id']}>
  <input type=text hidden=hidden name=news_id value={$_GET['id']}>
  
  <input type=submit value=Отправить комментарий>
</form></div>

file that is being processed
<?php
require_once ("../classes/comments.php");


if (isset($_POST)) 
{
  $new_com = new Comment($_POST);
  $new_com->addComment();
  print_r($_POST);
  echo "<pre>";
  print_r($new_com);
  echo "</pre>";
  unset($_POST);
  //header("Location: ".$_SERVER['HTTP_REFERER']);
}

print_r result
67fd6470a9a8474ba8e683dc9544cd30.png
Class and query
<?php
require_once ("db.php");

class Comment extends DB {
  public $content;
  public $date;
  public $user_id;
  public $news_id;
  public $login;

  public function __construct(array $a) {
    $this->content = $a['comment'];
    $this->date = date("Y-m-d H:i:s");
    $this->user_id = $a['user_id'];
    $this->news_id = $a['news_id'];
    $this->login = $a['login'];
  }

  public function addComment() {
    $quer = "INSERT INTO `coments`(`id`, `content`, `date`,`login`, `news_id`, `user_id`) VALUES ('','$this->content','$this->date','$this->login',$this->news_id','$this->user_id')";
    $add_com = DB::obj()->connect()->exec($quer);
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-11-16
@AFI19

first, I would remove the id filling,
then wrap all the properties in {$this->news_id}
and then just take a closer look and see the missing quote :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question