Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 KB | None | 0 0
  1. <?php
  2. header("Content-Type: text/html; charset=utf-8");
  3. ?>
  4.  
  5.  
  6.  
  7. <?
  8.  
  9. $hostName = "localhost";
  10. $userName = "root";
  11. $password = "";
  12. $databaseName = "my_form";
  13.  
  14. $con = mysql_connect($hostName, $userName, $password);
  15. if (!$con)
  16. //if (!($con = mysql_connect($hostName, $userName, $password)))
  17. {
  18. printf("ошибка при соединении с MySQL !\n");
  19. exit();
  20. }
  21.  
  22. if (!mysql_select_db($databaseName, $con))
  23. {
  24. printf("ошибка базы данных !");
  25. exit();
  26. }
  27.  
  28. mysql_query("SET NAMES 'utf8'");
  29.  
  30.  
  31. $con = mysql_connect($hostName, $userName, $password);
  32.  
  33. if (!$con)
  34. {
  35. die('Could not connect: ' . mysql_error());
  36. }
  37.  
  38. mysql_select_db($databaseName, $con);
  39.  
  40. $articleid = $_GET['id'];
  41.  
  42. if( ! is_numeric($articleid) )
  43. die('invalid articleid');
  44.  
  45. $query = "SELECT * FROM `comments` WHERE `articleid` =$articleid LIMIT 0 , 30";
  46.  
  47. $comments = mysql_query($query);
  48.  
  49. echo "<h1>User Comments</h1>";
  50.  
  51. while($row = mysql_fetch_array($comments, MYSQL_ASSOC))
  52. {
  53. $name = $row['name'];
  54. $email = $row['email'];
  55. $comment = $row['comment'];
  56. $timestamp = $row['timestamp'];
  57.  
  58. $name = htmlspecialchars($row['name'],ENT_QUOTES);
  59. $email = htmlspecialchars($row['email'],ENT_QUOTES);
  60. $comment = htmlspecialchars($row['comment'],ENT_QUOTES);
  61.  
  62. echo " <div style='margin:30px 0px;'>
  63. Name: $name<br />
  64. Email: $email<br />
  65. Comment: $comment<br />
  66. Timestamp: $timestamp
  67. </div>
  68. ";
  69. }
  70.  
  71.  
  72.  
  73.  
  74. if( $_POST )
  75. {
  76. $con = mysql_connect($hostName, $userName, $password);
  77.  
  78. if (!$con)
  79. {
  80. die('Could not connect: ' . mysql_error());
  81. }
  82.  
  83. mysql_select_db($databaseName, $con);
  84.  
  85. $users_name = $_POST['name'];
  86. $users_email = $_POST['email'];
  87. $users_comment = $_POST['comment'];
  88.  
  89. $users_name = mysql_real_escape_string($users_name);
  90. $users_email = mysql_real_escape_string($users_email);
  91. $users_comment = mysql_real_escape_string($users_comment);
  92.  
  93. $articleid = $_GET['id'];
  94.  
  95. if( ! is_numeric($articleid) ) {
  96.  
  97. die('invalid article id'); }
  98.  
  99.  
  100.  
  101. $query = "
  102. INSERT INTO `my_form`.`comments` (`id`, `name`, `email`,
  103. `comment`, `timestamp`, `articleid`) VALUES (NULL, '$users_name',
  104. '$users_email', , '$users_comment',
  105. CURRENT_TIMESTAMP, '$articleid');";
  106.  
  107. mysql_query($query);
  108.  
  109. echo "<h2>Thank you for your Comment!</h2>";
  110.  
  111. mysql_close($con);
  112. }
  113.  
  114.  
  115. ?>
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. <!---------------------------------------------------------------------------------------------------------------------->
  123.  
  124. <h1>This is index.php</h1>
  125.  
  126. <div><a href='page2.php?id=2'>Click here</a> to go to page2.php</div>
  127.  
  128. <div style='margin:20px; width:100px; height:100px; background:blue;'></div>
  129.  
  130. <!doctype html>
  131. <html lang=eng>
  132. <head>
  133. <meta charset=utf-8>
  134. <title>форма комментов</title>
  135. <!--[if IE 7 ]><html lang="en" class="no-js ie7 oldie"><![endif]-->
  136. <!--[if IE 8 ]><html lang="en" class="no-js ie8 oldie"><![endif]-->
  137. <!--[if IE 9 ]><html lang="en" class="no-js ie9"><![endif]-->
  138. <!--[if (gt IE 9)|!(IE)]><!-->
  139.  
  140. <script>
  141. function checkForm(form) {
  142.  
  143. var name = form.name.value;
  144. var n = name.match(/^[A-Za-zА-Яа-я ]*[A-Za-zА-Яа-я ]+$/);
  145. if (!n) {
  146. alert("Имя введено неверно, пожалуйста исправьте ошибку");
  147. return false;
  148. }
  149.  
  150.  
  151. var mail = form.mail.value;
  152. var m = mail.match(/^[A-Za-z0-9][A-Za-z0-9\._-]*[A-Za-z0-9_]*@([A-Za-z0-9]+([A-Za-z0-9-]*
  153. [A-Za-z0-9]+)*\.)+[A-Za-z]+$/);
  154. if (!m) {
  155. alert("E-mail введен неверно, пожалуйста исправьте ошибку");
  156. return false;
  157. }
  158. return true;
  159. }
  160. </script>
  161.  
  162. </head>
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. <body>
  170.  
  171.  
  172. <style>
  173. @charset "utf-8";
  174. /* CSS Document */
  175.  
  176. body {
  177. font-size:100%;
  178. font-family:Georgia, "Times New Roman", Times, serif;
  179. color:#3a3a3a;
  180. }
  181.  
  182. .body {
  183. width:576px;
  184. margin:0 auto;
  185. display:block;
  186. }
  187.  
  188. h1 {
  189. width:450px;
  190. height:62px;
  191. background:#3a3a3a;
  192. color:#fff;
  193. font-family:bebas;
  194. padding:15px 0px 0px 73px;
  195. letter-spacing:1px;
  196. font-size:2.2em;
  197. margin:0 auto;
  198. }
  199.  
  200. form {
  201. width:452px;
  202. margin:0 auto;
  203.  
  204. }
  205.  
  206. label {
  207. display:block;
  208. margin-top:15px;
  209. letter-spacing:2px;
  210. }
  211.  
  212.  
  213. help {
  214. display:none;
  215. font-size:90%;
  216.  
  217. }
  218.  
  219.  
  220. input:focus + .help {
  221. display:inline-block;
  222.  
  223.  
  224. }
  225.  
  226.  
  227.  
  228.  
  229.  
  230. input, textarea {
  231. width:439px;
  232. height:40px;
  233. background:#efefef;
  234. border-radius:5px;
  235. -moz-border-radius:5px;
  236. -webkit-border-radius:5px;
  237. border:1px solid #dedede;
  238. padding:10px;
  239. margin-top:3px;
  240. font-size:0.9em;
  241. color:#3a3a3a;
  242.  
  243. }
  244.  
  245.  
  246. input:required:invalid {
  247. border:1px solid red;
  248. }
  249.  
  250. textarea required:invalid {
  251. border:1px solid red;
  252. }
  253.  
  254.  
  255. input:focus, textarea:focus {
  256. border:1px solid #97d6eb;
  257. }
  258.  
  259. textarea {
  260. height:110px;
  261. font-family:Arial, Helvetica, sans-serif;
  262. background:#efefef;
  263. }
  264.  
  265. #submit {
  266.  
  267. background:#98FB98;
  268. z-index:2;
  269. display:inline;
  270. float:left;
  271. width:320px;
  272. height:36px;
  273. border:2;
  274. margin-top:20px;
  275. text-color:
  276. }
  277.  
  278. #submit:hover {
  279.  
  280. opacity:.85;
  281. cursor: pointer;
  282.  
  283. }
  284.  
  285.  
  286. #submit:active {
  287. border: 1px solid #20911e;
  288. box-shadow: 0 0 10px 5px #356b0b inset;
  289. -webkit-box-shadow:0 0 10px 5px #356b0b inset ;
  290. -moz-box-shadow: 0 0 10px 5px #356b0b inset;
  291. -ms-box-shadow: 0 0 10px 5px #356b0b inset;
  292. -o-box-shadow: 0 0 10px 5px #356b0b inset;
  293. }
  294.  
  295.  
  296.  
  297.  
  298.  
  299. </style>
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307. <ul>
  308.  
  309. <li>
  310. <h2>Оставить комнтарий</h2>
  311.  
  312.  
  313. <form method="post" action="" onSubmit="return checkForm(this)">
  314.  
  315. <label>*Ваше имя:</label>
  316. <input type="text" id="name" name="name" value="" required pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" aria-required="true" aria-describedby="name-format" placeholder="Введите здесь,например Jasmina"/>
  317. <span id="name-format" class="help">Format: firstname lastname</span>
  318.  
  319.  
  320. <label>Ваш e-mail:</label>
  321. <input type="text" id="email" name="email" required pattern="\S+@[a-z]+.[a-z]+" placeholder="Введите здесь,например jasmina@yandex.ru"/>
  322.  
  323.  
  324. <label>*Ваше сообщение:</label>
  325. <textarea id="comment" name="comment" cols="40" rows="6" placeholder="Введите здесь" required></textarea>
  326. <input type='hidden' name='articleid' id='articleid' value='<? echo $_POST['id']; ?>'/>
  327. <input type="checkbox" id="checkBoxId"><label for="checkBoxId">- для отправки сообщения поставте галочку</label>
  328.  
  329. <label for="fileFF">Прикрепить файл:</label>
  330. <label class="custom-file-input file-blue"><input type="file"></label>
  331.  
  332. <label>*Сколько будет 2+2? (Докажите,что вы не робот)</label>
  333. <input name="human" placeholder="Введите здесь" required />
  334.  
  335. <input type="hidden" name="page_id" value="" />
  336. <input id="submit" name="submit" type="submit" value="Отправить"/>
  337.  
  338. </form>
  339.  
  340. </body>
  341. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement