在数据库中检查时,HTML模式属性不起作用

时间:2017-09-20 19:22:28

标签: php html regex html5

大家好我在index.html中有一个表单。以下是两个代码片段,请查看并帮助我理清本问题末尾提到的问题。谢谢

<form method="post" action="subscribe.php" class="contactform center-block">

        <div class="row">
        <div class="form-group col-12 col-sm-6">
           <!-- <label for="userName">Name</label>-->
            <input
                   name="fullName" 
                   type="text" 
                   class="form-control"
                   pattern="[a-zA-Z][a-zA-Z ]{2,}" 
                   id="userName" 
                   placeholder="Enter your Full Name here" 
                   required
            >

        </div>

        </div>

        <div class="row">
            <div class="col-12 col-sm-12">
                <input 
                     type="submit" 
                     name="submit" 
                     id="submit1" 
                     value="Subscibe!"
                     class="submitBtn btn btn-primary ">
            </div>
        </div>

    </form>

这里是 subscribe.php

<?php 

 if(!empty($_POST)) {

$mysqli = new mysqli(
    'localhost',
    'username',
    'password',
    'dbname'
);


$admin = 'example@hello.com';
$useremail = $_POST['email'];
$subject = "My Subject";
$username = $_POST['fullName'];
$email = $_POST['email'];
$header = 'From ' . $email;

$message = <<<EMAIL

  message body.....

EMAIL;



// Check for connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}


//Insert our data

$sql = "INSERT INTO subscribe(fullName,email)VALUES(

'{$mysqli->real_escape_string($_POST['fullName'])}',
'{$mysqli->real_escape_string(($_POST['email']))}' )";

// Print Response from MySql

if (mysqli_query($mysqli, $sql)) {

    if(mail( $admin , $subject , $message, $header)){
    header('Location: http://www.example.com/');

    }

 } else {

    die("Error: {$mysqli->errno} : {$mysqli->error}");
 }

 // Close the connection

 $mysqli->close();

 }


 ?>

问题

MySql数据库已连接且工作正常,数据已插入但问题在于我在DB中查看订阅表并且 fullName列仍包含具有此值的行 59c29dc55ff88 即使我在上面的html表单中提到了输入标记中的模式。它在网页中正常工作,但当我查看数据库时,值以我提到的格式显示。我担心当提到模式属性时,有人可以在名称输入中插入这种类型的数据。

请指导我。谢谢你的帮助

0 个答案:

没有答案