Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require "DB.inc.php";
- unset($erroruser);
- $erroruser = array('nam' => 'Please enter name!', 'characters' => 'Name must be longer than 3 characters!', 'mail' => 'Please enter e-mail!', 'country' => 'Please enter country!');
- $vuz = $pdo ->prepare("SELECT country FROM cities");
- $vuz ->execute();
- $row = $vuz->fetchAll(PDO::FETCH_ASSOC);
- if ($_SERVER['REQUEST_METHOD'] == 'POST'){
- $name = trim(strip_tags($_POST['name']));
- $email = trim(strip_tags($_POST['email']));
- $country = $_POST['count'];
- if(!empty($name)){
- if(mb_strLen($name)>3){
- if (!empty($email)) {
- if (!empty($country)) {
- if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
- /*print_r($count);*/
- $vuz = $pdo->prepare("INSERT INTO users (name, email, country)
- VALUES (?,?,?)");
- $vuz->bindParam(1, $name);
- $vuz->bindParam(2, $email);
- $vuz->bindParam(3, $country);
- $vuz->execute();
- header('Location: Index.php');
- exit;
- }
- } else {
- echo $erroruser['country'];
- }
- } else {
- echo $erroruser['mail'];
- }
- } else {
- echo $erroruser['characters'];
- }
- } else {
- echo $erroruser['nam'];
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Form user</title>
- <link rel='stylesheet' type='text/css' href='style.css'/>
- </head>
- <body>
- <div>
- <form action="<?php echo $_SERVER["REQUEST_URI"]?>" method="POST" enctype="multipart/form-data">
- <p>
- <input <?php /*if(!empty($erroruser['nam'])){echo "style='border: red 1px solid;'";}*/?> type="text" name="name" placeholder="name" >
- </p>
- <p>
- <input class='text' type="email" name="email" placeholder="e-mail" >
- </p>
- <p>
- <select class='text' name="count">
- <option value="">select country</option>
- <?php
- foreach ($row as $item) {
- print "<option value=".$item['country'].'>'.$item['country']."</option>";
- }
- ?>
- </select>
- </p>
- <p>
- <input type="submit" value="add user">
- </p>
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement