Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用户已存在,请填写表单_Php_Mysql - Fatal编程技术网

Php 用户已存在,请填写表单

Php 用户已存在,请填写表单,php,mysql,Php,Mysql,这是我到目前为止注册用户的代码 现在我需要: 如果已使用用户名,则返回错误消息 如果字段为空,则显示错误消息 代码如下: //=============Configuring Server and Database======= $host = 'localhost'; $user = 'root'; $password = 'revilo'; //=============Data Base Information============

这是我到目前为止注册用户的代码

现在我需要:

  • 如果已使用用户名,则返回错误消息
  • 如果字段为空,则显示错误消息
代码如下:

//=============Configuring Server and Database=======
$host        =    'localhost';
$user        =    'root';
$password    =    'revilo';
//=============Data Base Information=================
$database    =    'dbsneaker';

$conn        =    mysql_connect($host,$user,$password) or die('Server Information is not Correct'); //Establish Connection with Server
mysql_select_db($database,$conn) or die('Database Information is not correct');

//===============End Server Configuration============

//=============Starting Registration Script==========

$userName    =    mysql_real_escape_string($_POST['txtUser']);

$password    =    mysql_real_escape_string($_POST['txtPassword']);


if(isset($_POST['btnRegister'])) //===When I will Set the Button to 1 or Press Button    to register
{
$query    =    "insert into bladmin(admin_usr_name, admin_pwd) values('$userName', '$password')";
$res    =    mysql_query($query);
header('location:success_register.php');
}

任何帮助都将不胜感激

我认为这将有助于

// Validate empty
if(!trim($userName) || !trim($password)){
    // Some field still empty
}else{
    // There's no empty field
    // Check user exists
    $checkQuerySql = "SELECT * FROM `bladmin` WHERE `admin_usr_name` = '$userName'";
    $checkQuery = mysql_query($checkQuerySql);
    if(mysql_fetch_assoc($checkQuery)){
        // User exists
    }else{
        // User doesnt exists
    }
}

非常感谢,帮了大忙