Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. <?php
  2. require "DB.inc.php";
  3. unset($erroruser);
  4. $erroruser = array('nam' => 'Please enter name!', 'characters' => 'Name must be longer than 3 characters!', 'mail' => 'Please enter e-mail!', 'country' => 'Please enter country!');
  5. $vuz = $pdo ->prepare("SELECT country FROM cities");
  6. $vuz ->execute();
  7.  
  8. $row = $vuz->fetchAll(PDO::FETCH_ASSOC);
  9.  
  10. if ($_SERVER['REQUEST_METHOD'] == 'POST'){
  11.  
  12. $name = trim(strip_tags($_POST['name']));
  13. $email = trim(strip_tags($_POST['email']));
  14. $country = $_POST['count'];
  15. if(!empty($name)){
  16. if(mb_strLen($name)>3){
  17. if (!empty($email)) {
  18. if (!empty($country)) {
  19.  
  20. if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
  21. /*print_r($count);*/
  22. $vuz = $pdo->prepare("INSERT INTO users (name, email, country)
  23. VALUES (?,?,?)");
  24. $vuz->bindParam(1, $name);
  25. $vuz->bindParam(2, $email);
  26. $vuz->bindParam(3, $country);
  27. $vuz->execute();
  28. header('Location: Index.php');
  29. exit;
  30. }
  31. } else {
  32. echo $erroruser['country'];
  33. }
  34. } else {
  35. echo $erroruser['mail'];
  36. }
  37. } else {
  38. echo $erroruser['characters'];
  39. }
  40. } else {
  41. echo $erroruser['nam'];
  42. }
  43. }
  44. ?>
  45. <!DOCTYPE html>
  46. <html>
  47. <head>
  48. <meta charset="UTF-8">
  49. <title>Form user</title>
  50. <link rel='stylesheet' type='text/css' href='style.css'/>
  51. </head>
  52. <body>
  53. <div>
  54. <form action="<?php echo $_SERVER["REQUEST_URI"]?>" method="POST" enctype="multipart/form-data">
  55. <p>
  56. <input <?php /*if(!empty($erroruser['nam'])){echo "style='border: red 1px solid;'";}*/?> type="text" name="name" placeholder="name" >
  57. </p>
  58. <p>
  59. <input class='text' type="email" name="email" placeholder="e-mail" >
  60. </p>
  61. <p>
  62. <select class='text' name="count">
  63. <option value="">select country</option>
  64. <?php
  65.  
  66. foreach ($row as $item) {
  67. print "<option value=".$item['country'].'>'.$item['country']."</option>";
  68. }
  69. ?>
  70. </select>
  71. </p>
  72. <p>
  73. <input type="submit" value="add user">
  74. </p>
  75. </form>
  76. </div>
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement