Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Content-Type: text/html; charset=utf-8");
- ?>
- <?
- $hostName = "localhost";
- $userName = "root";
- $password = "";
- $databaseName = "my_form";
- $con = mysql_connect($hostName, $userName, $password);
- if (!$con)
- //if (!($con = mysql_connect($hostName, $userName, $password)))
- {
- printf("ошибка при соединении с MySQL !\n");
- exit();
- }
- if (!mysql_select_db($databaseName, $con))
- {
- printf("ошибка базы данных !");
- exit();
- }
- mysql_query("SET NAMES 'utf8'");
- $con = mysql_connect($hostName, $userName, $password);
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db($databaseName, $con);
- $articleid = $_GET['id'];
- if( ! is_numeric($articleid) )
- die('invalid articleid');
- $query = "SELECT * FROM `comments` WHERE `articleid` =$articleid LIMIT 0 , 30";
- $comments = mysql_query($query);
- echo "<h1>User Comments</h1>";
- while($row = mysql_fetch_array($comments, MYSQL_ASSOC))
- {
- $name = $row['name'];
- $email = $row['email'];
- $comment = $row['comment'];
- $timestamp = $row['timestamp'];
- $name = htmlspecialchars($row['name'],ENT_QUOTES);
- $email = htmlspecialchars($row['email'],ENT_QUOTES);
- $comment = htmlspecialchars($row['comment'],ENT_QUOTES);
- echo " <div style='margin:30px 0px;'>
- Name: $name<br />
- Email: $email<br />
- Comment: $comment<br />
- Timestamp: $timestamp
- </div>
- ";
- }
- if( $_POST )
- {
- $con = mysql_connect($hostName, $userName, $password);
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db($databaseName, $con);
- $users_name = $_POST['name'];
- $users_email = $_POST['email'];
- $users_comment = $_POST['comment'];
- $users_name = mysql_real_escape_string($users_name);
- $users_email = mysql_real_escape_string($users_email);
- $users_comment = mysql_real_escape_string($users_comment);
- $articleid = $_GET['id'];
- if( ! is_numeric($articleid) ) {
- die('invalid article id'); }
- $query = "
- INSERT INTO `my_form`.`comments` (`id`, `name`, `email`,
- `comment`, `timestamp`, `articleid`) VALUES (NULL, '$users_name',
- '$users_email', , '$users_comment',
- CURRENT_TIMESTAMP, '$articleid');";
- mysql_query($query);
- echo "<h2>Thank you for your Comment!</h2>";
- mysql_close($con);
- }
- ?>
- <!---------------------------------------------------------------------------------------------------------------------->
- <h1>This is index.php</h1>
- <div><a href='page2.php?id=2'>Click here</a> to go to page2.php</div>
- <div style='margin:20px; width:100px; height:100px; background:blue;'></div>
- <!doctype html>
- <html lang=eng>
- <head>
- <meta charset=utf-8>
- <title>форма комментов</title>
- <!--[if IE 7 ]><html lang="en" class="no-js ie7 oldie"><![endif]-->
- <!--[if IE 8 ]><html lang="en" class="no-js ie8 oldie"><![endif]-->
- <!--[if IE 9 ]><html lang="en" class="no-js ie9"><![endif]-->
- <!--[if (gt IE 9)|!(IE)]><!-->
- <script>
- function checkForm(form) {
- var name = form.name.value;
- var n = name.match(/^[A-Za-zА-Яа-я ]*[A-Za-zА-Яа-я ]+$/);
- if (!n) {
- alert("Имя введено неверно, пожалуйста исправьте ошибку");
- return false;
- }
- var mail = form.mail.value;
- var m = mail.match(/^[A-Za-z0-9][A-Za-z0-9\._-]*[A-Za-z0-9_]*@([A-Za-z0-9]+([A-Za-z0-9-]*
- [A-Za-z0-9]+)*\.)+[A-Za-z]+$/);
- if (!m) {
- alert("E-mail введен неверно, пожалуйста исправьте ошибку");
- return false;
- }
- return true;
- }
- </script>
- </head>
- <body>
- <style>
- @charset "utf-8";
- /* CSS Document */
- body {
- font-size:100%;
- font-family:Georgia, "Times New Roman", Times, serif;
- color:#3a3a3a;
- }
- .body {
- width:576px;
- margin:0 auto;
- display:block;
- }
- h1 {
- width:450px;
- height:62px;
- background:#3a3a3a;
- color:#fff;
- font-family:bebas;
- padding:15px 0px 0px 73px;
- letter-spacing:1px;
- font-size:2.2em;
- margin:0 auto;
- }
- form {
- width:452px;
- margin:0 auto;
- }
- label {
- display:block;
- margin-top:15px;
- letter-spacing:2px;
- }
- help {
- display:none;
- font-size:90%;
- }
- input:focus + .help {
- display:inline-block;
- }
- input, textarea {
- width:439px;
- height:40px;
- background:#efefef;
- border-radius:5px;
- -moz-border-radius:5px;
- -webkit-border-radius:5px;
- border:1px solid #dedede;
- padding:10px;
- margin-top:3px;
- font-size:0.9em;
- color:#3a3a3a;
- }
- input:required:invalid {
- border:1px solid red;
- }
- textarea required:invalid {
- border:1px solid red;
- }
- input:focus, textarea:focus {
- border:1px solid #97d6eb;
- }
- textarea {
- height:110px;
- font-family:Arial, Helvetica, sans-serif;
- background:#efefef;
- }
- #submit {
- background:#98FB98;
- z-index:2;
- display:inline;
- float:left;
- width:320px;
- height:36px;
- border:2;
- margin-top:20px;
- text-color:
- }
- #submit:hover {
- opacity:.85;
- cursor: pointer;
- }
- #submit:active {
- border: 1px solid #20911e;
- box-shadow: 0 0 10px 5px #356b0b inset;
- -webkit-box-shadow:0 0 10px 5px #356b0b inset ;
- -moz-box-shadow: 0 0 10px 5px #356b0b inset;
- -ms-box-shadow: 0 0 10px 5px #356b0b inset;
- -o-box-shadow: 0 0 10px 5px #356b0b inset;
- }
- </style>
- <ul>
- <li>
- <h2>Оставить комнтарий</h2>
- <form method="post" action="" onSubmit="return checkForm(this)">
- <label>*Ваше имя:</label>
- <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"/>
- <span id="name-format" class="help">Format: firstname lastname</span>
- <label>Ваш e-mail:</label>
- <input type="text" id="email" name="email" required pattern="\S+@[a-z]+.[a-z]+" placeholder="Введите здесь,например jasmina@yandex.ru"/>
- <label>*Ваше сообщение:</label>
- <textarea id="comment" name="comment" cols="40" rows="6" placeholder="Введите здесь" required></textarea>
- <input type='hidden' name='articleid' id='articleid' value='<? echo $_POST['id']; ?>'/>
- <input type="checkbox" id="checkBoxId"><label for="checkBoxId">- для отправки сообщения поставте галочку</label>
- <label for="fileFF">Прикрепить файл:</label>
- <label class="custom-file-input file-blue"><input type="file"></label>
- <label>*Сколько будет 2+2? (Докажите,что вы не робот)</label>
- <input name="human" placeholder="Введите здесь" required />
- <input type="hidden" name="page_id" value="" />
- <input id="submit" name="submit" type="submit" value="Отправить"/>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement