以下代码能够注册用户,但无法检查用户是否已存在。请修改代码以检查用户是否已存在。我正在使用从 navision 表中获取数据的 sql server 2012。该代码包含两个部分,即 php 代码和 html 代码(其中包含注册表单)
<?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';?>