Php Mysql - 用空命令检查变量重复

时间:2016-12-09 12:02:17

标签: php mysqli

我有用户在我的网页中添加表单。

这样的代码;

if(isset($_POST['submitted']) ==1) {

        $name = mysqli_real_escape_string($dbc, $_POST['name']);
        $surname = mysqli_real_escape_string($dbc, $_POST['surname']);
        $date = mysqli_real_escape_string($dbc, $_POST['date']);
        $email = mysqli_real_escape_string($dbc, $_POST['email']);
        $password = mysqli_real_escape_string($dbc, $_POST['password']);
        $city = mysqli_real_escape_string($dbc, $_POST['city']);

        $q = "INSERT INTO users (name, surname, date, email, password, city) VALUES('$name', '$surname', '$date', '$email', '$password', '$city')";
        $r = mysqli_query($dbc, $q); 


    if($r) {
        $message = 'User was added';
    }else{
        $message = 'User could not be added because: '.mysqli_error($dbc);
        $message .= '<p>'.$q.'</p>';
        }
    }

我的提交按钮是:

<button type="submit" class="btn btn-default">Add User</button>
<?php if(isset($message)) { echo $message; }?>
<input type="hidden" name="submitted" value="1">

我想使用该帖子按钮检查数据库表中的现有值。 我怎样才能在这篇文章中检查相同的值?

1 个答案:

答案 0 :(得分:0)

你可以这样做:

orderedDict