function set_answer($question_id) { /* * $answer_sanitized string */ $answer_sanitized = pg_escape_string($_POST['answer']); // to sanitize answer $dbconn = pg_connect("host=localhost port=5432 dbname=noaa user=noaa password=123"); // to put answer and question_id to Answers -table $result = pg_query_params($dbconn, 'INSERT INTO answers (answer, question_id, user_id) VALUES ($1, $2, $3)', array($answer_sanitized, $question_id, $_SESSION['login']['user_id'])); // to redirect the user if ($result) { header("Location: /pgCodesS/index.php?" . "answer_sent" . "&" . "question_id=" . $question_id); } else { header("Location: /pgCodesS/index.php?" . "answer_not_sent" . "&" . "question_id=" . $question_id); } } // Let's fire! /** Tarkasta, ettei vastaus ole tyh\"{a} ja salli vain kirjautunet * k\"{a}ytt\"{a}j\"{a} */ if (!empty($_POST['answer'])) { if (check_user_status()) { set_answer(get_questionID_at_question()); } } else { header("Location: /pgCodesS/index.php"); } ob_flush();
/** Luo HTML tageille * @param @tags string */ function create_tags_at_question($tags) { echo "<label for='tags'>Tags</label>" . "<input name='question[tags]' type='text' cols='92' class='tags' id='required'" . " value='" . $tags . "' />"; echo "<div id='notice'><p>" . "Please, use at least one tag and maximum five tags. Separate them by commas (,)." . "</p></div>"; } // TODO /** Luo kysymys muokkausn\"{a}kym\"{a}ss\"{a} * @param $question_id integer */ function create_edit_box($question_id) { /** * $body string * $title string * $tags string */ $body = get_question_body($question_id); $title = get_question_title($question_id); $tags = get_question_tags($question_id); echo "<form id='update_question_form' method='post' " . "action='./handlers/update_question.php" . "'>"; echo "<fieldset>" . create_title_at_question($title) . create_body_at_question($body) . create_tags_at_question($tags) . "</fieldset>"; echo "<input class='update_question' onclick='checkFields();' type='submit' value='Update Your Question' /></form>"; } // Let's fire! /** Luo muokkauslaatikko */ create_edit_box(get_questionID_at_question());