Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. <input value='' name="question" id="question" class="form-
  2. control" placeholder="q">
  3.  
  4. <input value='' name="answer" id="answer" class="form-control"
  5. placeholder="a">
  6.  
  7. var inputQ = $('<input/>', {
  8. type: 'text',
  9. name: 'DynamicExtraField[]',
  10. placeholder: 'Вопрос',
  11. value: '',
  12. class: 'form-control'
  13. }).appendTo(div);
  14.  
  15. var inputA = $('<input/>', {
  16. type: 'text',
  17. name: 'DynamicExtraField[]',
  18. placeholder: 'Ответ',
  19. value: '',
  20. class: 'form-control',
  21. }).appendTo(div);
  22.  
  23. var question= $('#question').val();
  24.  
  25. var formValuesArray = [];
  26. for(var i = 0;i<form.elements.length;i++){
  27. formValuesArray.push(form.elements[i].value); //Или то что нужно
  28. }
  29.  
  30. $.post(
  31. "Url",
  32. $("#myForm").serializeArray();
  33. onCompleteCallback
  34. );
  35.  
  36. <form id="form" method="POST" action="index.php">
  37.  
  38. <input value='' name="question" id="question" class="form-
  39. control" placeholder="q">
  40.  
  41. <input value='' name="answer" id="answer" class="form-control"
  42. placeholder="a">
  43.  
  44. <input type="submit" value="Отправить">
  45.  
  46. </form>
  47.  
  48. var inputQ = $('<input/>', {
  49. type: 'text',
  50. name: 'DynamicExtraField[]',
  51. placeholder: 'Вопрос',
  52. value: '',
  53. class: 'form-control'
  54. }).appendTo('#form');
  55.  
  56. var inputA = $('<input/>', {
  57. type: 'text',
  58. name: 'DynamicExtraField[]',
  59. placeholder: 'Ответ',
  60. value: '',
  61. class: 'form-control',
  62. }).appendTo('#form');
  63.  
  64. $host = "localhost";
  65. $db = "test";
  66. $user = "root";
  67. $password = '12345';
  68.  
  69. $data_base = new PDO ("mysql:host=$host;dbname=$db","$user","$password" );
  70.  
  71. $data_base->exec("set names utf8");
  72. $data_base->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  73.  
  74. // Подготавливаем запрос
  75. $result = $data_base->prepare("
  76. INSERT INTO `table` (question, answer)
  77. VALUES (?, ?)
  78. ");
  79. // Выполняем запрос
  80. $result->execute( array(
  81. $_POST['question'],
  82. $_POST['answer']
  83. ) );
  84.  
  85. // Если произошла ошибка, уведомляем
  86. if ( !$result ) {
  87. echo 'Error!';
  88. break;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement