Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <input value='' name="question" id="question" class="form-
- control" placeholder="q">
- <input value='' name="answer" id="answer" class="form-control"
- placeholder="a">
- var inputQ = $('<input/>', {
- type: 'text',
- name: 'DynamicExtraField[]',
- placeholder: 'Вопрос',
- value: '',
- class: 'form-control'
- }).appendTo(div);
- var inputA = $('<input/>', {
- type: 'text',
- name: 'DynamicExtraField[]',
- placeholder: 'Ответ',
- value: '',
- class: 'form-control',
- }).appendTo(div);
- var question= $('#question').val();
- var formValuesArray = [];
- for(var i = 0;i<form.elements.length;i++){
- formValuesArray.push(form.elements[i].value); //Или то что нужно
- }
- $.post(
- "Url",
- $("#myForm").serializeArray();
- onCompleteCallback
- );
- <form id="form" method="POST" action="index.php">
- <input value='' name="question" id="question" class="form-
- control" placeholder="q">
- <input value='' name="answer" id="answer" class="form-control"
- placeholder="a">
- <input type="submit" value="Отправить">
- </form>
- var inputQ = $('<input/>', {
- type: 'text',
- name: 'DynamicExtraField[]',
- placeholder: 'Вопрос',
- value: '',
- class: 'form-control'
- }).appendTo('#form');
- var inputA = $('<input/>', {
- type: 'text',
- name: 'DynamicExtraField[]',
- placeholder: 'Ответ',
- value: '',
- class: 'form-control',
- }).appendTo('#form');
- $host = "localhost";
- $db = "test";
- $user = "root";
- $password = '12345';
- $data_base = new PDO ("mysql:host=$host;dbname=$db","$user","$password" );
- $data_base->exec("set names utf8");
- $data_base->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- // Подготавливаем запрос
- $result = $data_base->prepare("
- INSERT INTO `table` (question, answer)
- VALUES (?, ?)
- ");
- // Выполняем запрос
- $result->execute( array(
- $_POST['question'],
- $_POST['answer']
- ) );
- // Если произошла ошибка, уведомляем
- if ( !$result ) {
- echo 'Error!';
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement