Я добавил новую строку в базу данных, добавил поле ввода на страницу, внес некоторые изменения (неуверенно) в файл с классами, но при отправке сообщения второе поле не работает и в базе ничего не появляется.
Кто-нибудь может помочь с данным вопросом. Если что, могу более детально все объяснить и показать код.
Есть файл, называется profile.php, в нем вот этот кусок кода:
<form onsubmit="Profile.ask('<?php echo $profileInfo['username']; ?>'); return false;" class="profile_question_form" action="/<?php echo $profileInfo['username']; ?>/ask" method="post">
<input autocomplete="off" type="hidden" name="authenticity_token" value="<?php echo auth::getAuthenticityToken(); ?>">
<b><textarea name="questionText"></textarea></b> // Я дублирую эту строку, задаю новый name
<div class="form_actions">
<span id="question_word_counter">300</span>
<div class="main_actions">
<?php
if ( auth::isSession() && $profileInfo['anonymousQuestions'] == DISABLE_ANONYMOUS_QUESTIONS ) {
?>
<input id="anonymous_checkbox" disabled="disabled" name="anonymous_checkbox" type="checkbox" style="margin-top: 7px">
<label for="anonymous_checkbox" class="noselect strikeout"><?php echo $LANG['label-anonymous-ask']; ?></label>
<?php
} elseif ( auth::isSession() && $profileInfo['anonymousQuestions'] == ENABLE_ANONYMOUS_QUESTIONS ) {
?>
<input id="anonymous_checkbox" checked="checked" name="anonymous_checkbox" type="checkbox" style="margin-top: 7px">
<label for="anonymous_checkbox" class="noselect"><?php echo $LANG['label-anonymous-ask']; ?></label>
<?php
}
?>
</div>
<button class="primary_btn" value="ask"><?php echo $LANG['action-ask']; ?></button>
</div>
</form>
Потом перехожу в файл с классами и тут вот такой вот код (я понимаю, что тут нужно править, но не могу сделать так, чтобы все работало):
class questions extends db_connect
{
private $requestFrom = 0;
public function __construct($dbo = NULL)
{
parent::__construct($dbo);
}
public function count()
{
$stmt = $this->db->prepare("SELECT count(*) FROM qa WHERE toUserId = (:toUserId) AND replyAt = 0 AND removeAt = 0");
$stmt->bindParam(":toUserId", $this->requestFrom, PDO::PARAM_INT);
$stmt->execute();
return $number_of_rows = $stmt->fetchColumn();
}
public function add_to_db($questionText, $language)
{
$currentTime = time();
$stmt = $this->db->prepare("INSERT INTO qa_db (question, lang, createAt) value (:question, :lang, :createAt)");
$stmt->bindParam(":question", $questionText, PDO::PARAM_STR);
$stmt->bindParam(":lang", $language, PDO::PARAM_STR);
$stmt->bindParam(":createAt", $currentTime, PDO::PARAM_INT);
$stmt->execute();
}
public function add($questionText, $toUserId, $fromUserId = 0, $questionType = 0)
{
$result = array("error" => true,
"error_code" => ERROR_UNKNOWN);
if (strlen($questionText) == 0) {
return $result;
}
$currentTime = time();
$ip_addr = helper::ip_addr();
$u_agent = helper::u_agent();
$stmt = $this->db->prepare("INSERT INTO qa (toUserId, fromUserId, fromAccount, questionType, question, addedToListAt, createAt, ip_addr, u_agent) value (:toUserId, :fromUserId, :fromAccount, :questionType, :question, :addedToListAt, :createAt, :ip_addr, :u_agent)");
$stmt->bindParam(":toUserId", $toUserId, PDO::PARAM_INT);
$stmt->bindParam(":fromUserId", $fromUserId, PDO::PARAM_INT);
$stmt->bindParam(":fromAccount", $this->requestFrom, PDO::PARAM_INT);
$stmt->bindParam(":questionType", $questionType, PDO::PARAM_INT);
$stmt->bindParam(":question", $questionText, PDO::PARAM_STR);
$stmt->bindParam(":addedToListAt", $currentTime, PDO::PARAM_INT);
$stmt->bindParam(":createAt", $currentTime, PDO::PARAM_INT);
$stmt->bindParam(":ip_addr", $ip_addr, PDO::PARAM_STR);
$stmt->bindParam(":u_agent", $u_agent, PDO::PARAM_STR);
if ($this->requestFrom != $toUserId) {
$gcm = new gcm($this->db, $toUserId);
$gcm->setData(GCM_NOTIFY_QUESTION, "You have received new question", 0);
$gcm->send();
}
if ($stmt->execute()) {
$result = array("error" => false,
"error_code" => ERROR_SUCCESS,
"questionId" => $this->db->lastInsertId());
}
return $result;
}
public function remove($questionId)
{
$result = array("error" => true);
$questionInfo = $this->info($questionId);
if ($questionInfo['error'] === true) {
return $result;
}
if ($questionInfo['toUserId'] != $this->requestFrom) {
return $result;
}
if ($questionInfo['replyAt'] != 0) {
return $result;
}
$currentTime = time();
$stmt = $this->db->prepare("UPDATE qa SET removeAt = (:removeAt) WHERE id = (:questionId)");
$stmt->bindParam(":questionId", $questionId, PDO::PARAM_INT);
$stmt->bindParam(":removeAt", $currentTime, PDO::PARAM_INT);
if ($stmt->execute()) {
$result = array("error" => false);
}
return $result;
}
public function delete($questionId)
{
$result = array("error" => true);
$questionInfo = $this->info($questionId);
if ($questionInfo['error'] === true) {
return $result;
}
if ($questionInfo['replyAt'] != 0) {
return $result;
}
$currentTime = time();
$stmt = $this->db->prepare("UPDATE qa SET removeAt = (:removeAt) WHERE id = (:questionId)");
$stmt->bindParam(":questionId", $questionId, PDO::PARAM_INT);
$stmt->bindParam(":removeAt", $currentTime, PDO::PARAM_INT);
if ($stmt->execute()) {
$result = array("error" => false);
}
return $result;
}
public function restore($questionId)
{
$result = array("error" => true);
$questionInfo = $this->info($questionId);
if ($questionInfo['error'] === true) {
return $result;
}
$stmt = $this->db->prepare("UPDATE qa SET removeAt = 0 WHERE id = (:questionId)");
$stmt->bindParam(":questionId", $questionId, PDO::PARAM_INT);
if ($stmt->execute()) {
$result = array("error" => false);
}
return $result;
}
public function edit($questionId, $questionText)
{
$result = array("error" => true);
$questionInfo = $this->info($questionId);
if ($questionInfo['error'] === true) {
return $result;
}
$stmt = $this->db->prepare("UPDATE qa SET question = (:questionText) WHERE id = (:questionId)");
$stmt->bindParam(":questionId", $questionId, PDO::PARAM_INT);
$stmt->bindParam(":questionText", $questionText, PDO::PARAM_STR);
if ($stmt->execute()) {
$result = array("error" => false);
}
return $result;
}