次のコードはユーザーを登録できますが、ユーザーが既に存在するかどうかを確認できません。コードを変更して、ユーザーが既に存在するかどうかを確認してください。navision テーブルからデータを取得している SQL Server 2012 を使用しています。コードには、php コードと html コード (登録フォームを含む) の 2 つのセクションが含まれています。
<?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';?>