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
}
}
非常感谢,帮了大忙