Answer the question
In order to leave comments, you need to log in
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>
<?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']);
}
<?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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question