使用ODBC和php注册页面以检查sql server 2012中是否存在用户
以下代码可以注册用户,但无法检查该用户是否已存在。请修改代码以检查用户是否已存在。我正在使用sql server 2012,它正在从navision表中获取数据。该代码包含两个部分,即php代码和包含注册表的html代码使用ODBC和php注册页面以检查sql server 2012中是否存在用户,php,sql-server,odbc,Php,Sql Server,Odbc,以下代码可以注册用户,但无法检查该用户是否已存在。请修改代码以检查用户是否已存在。我正在使用sql server 2012,它正在从navision表中获取数据。该代码包含两个部分,即php代码和包含注册表的html代码 <?php include 'core/database/conn.php'; include 'includes/overall/header.php'; // Process the POST data. if (isset($_POST['log22'])){ $
<?php
include 'core/database/conn.php';
include 'includes/overall/header.php';
// Process the POST data.
if (isset($_POST['log22'])){
$username = $_POST['username'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm'];
$email = $_POST['email'];
//echo $getemail;
//echo "<script>alert('The Email is already registered');</script>";
$id=md5(rand(1,123));
$id='ADM'.strtoupper(substr($id,0,10));
$username = strtoupper($username);
$password = substr(md5($password),0,9);
$email = strtoupper($email);
//header ('Location: register.php');
$sql = "INSERT INTO[ICPAK_FORMS].[dbo].[ICPAK\$User Register](
[ID],[Username],[Password],[Email])
VALUES ('$id','$username','$password','$email')";
global $DBCONN;
odbc_exec($DBCONN,$sql);
}
?>
<h1>Register</h1>
<!----><script type="text/javascript" src="js/regform.js"></script>
<form id="formreg" name="formreg" method="post" action="register.php" onSubmit="return regformValidation()">
<ul>
<li>
Username:<br/><input type="text" name="username" value="<?php //if(isset($_POST['username'])){ echo $_POST['username']; } ?>"/>
</li>
<li>
Password:<br/> <input minlength="5" type="password" name="password" value="<?php //if(isset($_POST['password'])){ echo $_POST['password']; } ?>"/>
</li>
<li>
Confirm Password:<br/><input type="password" name="confirm" value="<?php //if(isset($_POST['confirm'])){ echo $_POST['confirm']; } ?>" />
</li>
<li>
E-mail<br/>
<input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])){ echo $_POST['email']; } ?>"/>
</li>
<li>
<input type="submit" value="submit" /><input type="hidden" name="log22" id="log22" value="Login" /></td>
</li>
<li>
<table>
<tr><td colspan="2">If you are registered click <a href="login.php">here</a> to Login</td><tr>
</table>
</li>
</ul>
</form>
<?php include 'includes/overall/footer.php';?>
写这个
$sql_select = "select * from [ICPAK_FORMS].[dbo].[ICPAK\$User Register] where [Username] = $username";
$queryresult = odbc_exec($DBCONN,$sql_select);
if ( odbc_num_rows($queryresult) > 0 ) {
{
// code for insert
}
else {
// show error that username already exist.
}
您只需检查输入用户名的用户是否存在,您可以通过下面的方法进行检查。。乙二醇
$result = odbc_exec( $connection, "SELECT username FROM users_table WHERE username like '$username' ");
if ( odbc_num_rows($queryresult) > 0) {
echo 'User with this name already exist.. Please select a different username';
....
....
// your logic what you want to do after that
}
else{
//Save and Register User
}
我建议你自己努力去做,如果你努力后失败了,你应该在这里问。。无论如何,祝你好运在这里提问之前,你至少应该自己做一件事。去检查一下,学习如何使用教程来做这件事。您的实际代码非常适合sql在insert/exists问题旁边插入它。如果您得到答案,请接受答案。@YogeshSuthar我这样做只是为了让他理解这样做的逻辑,我已经更改了代码。。谢谢你的帮助。。谢谢你