Code:
Warning: sqlsrv_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Registro\register.php on line 32 Warning: sqlsrv_query() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Registro\register.php on line 63 Failed to create a new account, please try again later Warning: sqlsrv_close() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Registro\register.php on line 87
Code:
<?php
require_once("PHPMailer/class.phpmailer.php");
require_once("recaptchalib.config.php");
require_once("recaptchalib.php");
require_once("config.php");
$user_ip = $_SERVER["REMOTE_ADDR"];
$username = isset($_POST["username"]) ? sqlsrv_escape_string(trim($_POST["username"])) : "";
$password = isset($_POST["password"]) ? sqlsrv_escape_string(trim($_POST["password"])) : "";
$password2 = isset($_POST["password2"]) ? sqlsrv_escape_string(trim($_POST["password2"])) : "";
$email = isset($_POST["email"]) ? sqlsrv_escape_string(trim($_POST["email"])) : "";
$verifyKey = isset($_GET["verifyKey"]) ? sqlsrv_escape_string(trim($_GET["verifyKey"])) : "";
$errors = array();
$success = "";
$activationKey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();
if (isset($_POST["submit"])) {
$conn = sqlsrv_connect($db_host, $connectionInfo);
$sql = "SELECT UserID FROM PS_UserData.dbo.Users_Master WHERE UserID = ?";
$params = array($username);
$options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$result = [MENTION=806297]sql[/MENTION]srv_query($conn, $sql, $params, $options);
//Validate username
if(empty($username)) {
$errors["username"] = "Please provide a user name.";
} else if(strlen($username) < 3 || strlen($username) > 16) {
$errors["username"] = "User name must be between 3 and 16 characters in length.";
} else if(ctype_alnum($username) === false) {
$errors["username"] = "User name must consist of numbers and letters only.";
} else if(sqlsrv_num_rows($result)) {
$errors["username"] = "User name already exists, please choose a different user name.";
}
//Validate user password.
if(empty($password)) {
$errors["password"] = "Please provide a password.";
} else if(strlen($password) < 3 || strlen($password) > 16) {
$errors["password"] = "Password must be between 3 and 16 characters in length.";
} else if($password != $password2) {
$errors["password2"] = "Passwords do not match.";
}
// Validate Email and Answer
if(empty($email)) {
$errors["email"] = "Please provide your email.";
} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors["email"] = "Invalid email format";
}
// Add the new account to the database if no previous errors have occurred.
if(count($errors) == 0) {
// AddUser Query & Parameters
$addUser = "INSERT INTO PS_UserData.dbo.Users_Master(UserID,Pw,JoinDate,Admin,AdminLevel,UseQueue,Status,Leave,LeaveDate,UserType,Point,UserIp) VALUES (?,?,GETDATE(),0,0,0,-5,0,GETDATE(),'N',0,?)";
$addUser_params = array($username, $password, $user_ip);
// VerifyUser Query & Parameters
$verifyUser = "INSERT INTO PS_UserData.dbo.User_Verification(UserID, VerifyKey, email) VALUES(?, ?, ?)";
$verifyUser_params = array($username, $activationKey, $email);
if(sqlsrv_query($conn, $addUser, $addUser_params) && sqlsrv_query($conn, $verifyUser, $verifyUser_params)) {
$success = "Account ".$username." successfully created!";
} else {
$errors["query"] = "Failed to create a new account, please try again later";
}
$mail_for = "register";
require_once("mail.php");
if($mail->Send()) {
$success .= "<br>An email has been sent to ".$email." with an activation key. Please check your mail to complete registration. <br />If the email is not in your main inbox please check you're spam folder or disable spam filtering.";
} else {
$errors["emailsend"] = "Validation email failed to send. Contact an administrator.";
}
}
if(count($errors) != 0){
foreach($errors as $error) {
echo $error;
}
} else {
echo $success;
}
sqlsrv_close($conn);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
require_once('recaptchalib.config.php');
require_once('recaptchalib.php');
?>
<title>Registration</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<style type="text/css">#error {color:#ff0000; list-style:none;}</style>
<script type="text/javascript">var RecaptchaOptions = {theme:'clean'};</script>
</head>
<body>
<h3>Account Registration</h3>
<form action="" method="post">
<div style="width:436px; border:1px solid #000000; padding:16px;">
Username
<input name="username" value="<?php if(isset($_POST['username'])){ echo $_POST['username']; } ?>" style="width:100%;" />
<div style="height: 5px;"> </div>
Password
<input name="password" type="password" value="<?php if(isset($_POST['password'])){ echo $_POST['password']; } ?>" style="width:100%;" />
<div style="height: 5px;"> </div>
Confirm Password
<input name="password2" type="password" value="<?php if(isset($_POST['password2'])){ echo $_POST['password2']; } ?>" style="width:100%;" />
<div style="height: 5px;"> </div>
Email
<input name="email" style="width:100%;" />
<div style="height: 5px;"> </div>
<input type="submit" name="submit" value="Create Account" />
</div>
</form>
</body>
</html>






