Can someone suggest me, what should I do?
Sending error:
Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\register.php:46 Stack trace: #0 C:\xampp\htdocs\register.php(115): AddAccount('asdxxas', '123123', '123123') #1 {main} thrown in C:\xampp\htdocs\register.php on line 46
<!-- Simple style block for the form -->
<style type="text/css">
body { background-color: #ccc; }
input { width: 200px; background-color: #666; border: 1px solid #000; color: #fff; height: 25px; padding-left: 5px; margin-bottom: 3px; }
input:hover { background-color: #333; }
input[type=submit]:hover { cursor: pointer; }
</style>
<?php
function AddAccount($user, $pass, $pass2) {
# Config settings. Change it to your server, username, password and connection type.
$dbType = "sqlsrv"; # Types: sqlsrv (need drivers), odbc08 (SQL Server 2008 and below), odbc12 (SQL Server 2012)
$dbServer = "localhost"; # SQL Server Name / IP
$dbName = "account"; # Database name
$dbUser = "sa"; # SQL Server Username
$dbPass = "1234"; # SQ: Server Password
# DOn't touch unless you know what you are doing.
$adduser = "INSERT INTO USER_PROFILE (user_no,user_id,user_pwd,resident_no,user_type,lo gin_flag,login_tag,server_id) VALUES (?,?,?,'801011000000','1','0','Y','000')";
$getuser = "SELECT user_id FROM USER_PROFILE WHERE user_id = ?";
$dk_time=strftime("%y%m%d%H%M%S");
list($usec1, $sec1) = explode(" ",microtime());
$user_no=$dk_time.substr($usec1,2,2);
$auparams = array($user_no, $user, md5($pass));
$guparams = array($user);
if(empty($user) || empty($pass) || empty($pass2)) {
echo "<br>You didn't fill in all fields. <a href='javascript:history.back()'>Go Back</a>";
} elseif($pass != $pass2) {
echo "<br>The passwords do not match. <a href='javascript:history.back()'>Go Back</a>";
} elseif($pass == $user) {
echo "<br>The username and password can't be the same. <a href='javascript:history.back()'>Go Back</a>";
} elseif(!preg_match("/^[0-9a-zA-Z]{3,15}$/i", $user)) {
echo "<br>Enter a username with only 0-9, a-z and A-Z. <a href='javascript:history.back()'>Go Back</a>";
} elseif(!preg_match("/^[0-9a-zA-Z]{3,15}$/i", $pass)) {
echo "<br>Enter a password with only 0-9, a-z and A-Z. <a href='javascript:history.back()'>Go Back</a>";
} elseif(strlen($user) < 3 || strlen($user) > 15) {
echo "<br>The username must be between 3 and 15 characters long. <a href='javascript:history.back()'>Go Back</a>";
} elseif(strlen($pass) < 3 || strlen($pass) > 15) {
echo "<br>The password must be between 3 and 15 characters long. <a href='javascript:history.back()'>Go Back</a>";
} else {
switch($dbType) {
case 'sqlsrv':
$connectionInfo = array( "Database"=>$dbName, "UID"=>$dbUser, "PWD"=>$dbPass);
$conn = sqlsrv_connect( $dbServer, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$gd = sqlsrv_query( $conn, $getuser, $guparams);
if (sqlsrv_num_rows($gd) > 0) {
echo "<br>This username is already registered. <a href='javascript:history.back()'>Go Back</a>";
} else {
$stmt = sqlsrv_query( $conn, $adduser, $auparams);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
} else {
return 1;
}
}
break;
case 'odbc08':
$conn = odbc_connect("Driver={SQL Server Native Client 10.0};Server=" . $dbServer . ";Database=" . $dbName . ";", $dbUser, $dbPass);
if( $conn === false ) {
die( print_r( odbc_error()));
}
$gd = odbc_prepare($conn, $getuser);
$gdexe = odbc_execute($gd, $guparams);
if(odbc_num_rows($gd) > 0) {
echo "<br>This username is already registered. <a href='javascript:history.back()'>Go Back</a>";
} else {
$stmt = odbc_prepare($conn, $adduser);
$execute = odbc_execute($stmt, $auparams);
if( $execute === false ) {
die( print_r( odbc_error()));
} else {
return 1;
}
}
break;
case 'odbc12':
$conn = odbc_connect("Driver={SQL Server Native Client 11.0};Server=" . $dbServer . ";Database=" . $dbName . ";", $dbUser, $dbPass);
if( $conn === false ) {
die( print_r( odbc_error()));
}
$gd = odbc_prepare($conn, $getuser);
$gdexe = odbc_execute($gd, $guparams);
if(odbc_num_rows($gd) > 0) {
echo "<br>This username is already registered. <a href='javascript:history.back()'>Go Back</a>";
} else {
$stmt = odbc_prepare($conn, $adduser);
$execute = odbc_execute($stmt, $auparams);
if( $execute === false ) {
die( print_r( odbc_error()));
} else {
return 1;
}
}
break;
}
}
}
if(isset($_POST['register'])) {
if(AddAccount($_POST['username'], $_POST['password'], $_POST['password2']) == 1) {
echo 'Account registered.';
echo '<br><strong>Username:</strong> ' . $_POST['username'];
echo '<br><strong>Password:</strong> ' . $_POST['password'];
} else {
echo '<br><br>Registration failed.';
}
} else {
# Register form, I don't provide syling.
?>
<form method="post">
<input type="text" name="username" placeholder="Username" /><br>
<input type="password" name="password" placeholder="Password" /><br>
<input type="password" name="password2" placeholder="Repeat password" /><br>
<input type="submit" name="register" value="Register" />
</form>
<?php
}
?>
<style type="text/css">
body { background-color: #ccc; }
input { width: 200px; background-color: #666; border: 1px solid #000; color: #fff; height: 25px; padding-left: 5px; margin-bottom: 3px; }
input:hover { background-color: #333; }
input[type=submit]:hover { cursor: pointer; }
</style>
<?php
function AddAccount($user, $pass, $pass2) {
# Config settings. Change it to your server, username, password and connection type.
$dbType = "sqlsrv"; # Types: sqlsrv (need drivers), odbc08 (SQL Server 2008 and below), odbc12 (SQL Server 2012)
$dbServer = "localhost"; # SQL Server Name / IP
$dbName = "account"; # Database name
$dbUser = "sa"; # SQL Server Username
$dbPass = "1234"; # SQ: Server Password
# DOn't touch unless you know what you are doing.
$adduser = "INSERT INTO USER_PROFILE (user_no,user_id,user_pwd,resident_no,user_type,lo gin_flag,login_tag,server_id) VALUES (?,?,?,'801011000000','1','0','Y','000')";
$getuser = "SELECT user_id FROM USER_PROFILE WHERE user_id = ?";
$dk_time=strftime("%y%m%d%H%M%S");
list($usec1, $sec1) = explode(" ",microtime());
$user_no=$dk_time.substr($usec1,2,2);
$auparams = array($user_no, $user, md5($pass));
$guparams = array($user);
if(empty($user) || empty($pass) || empty($pass2)) {
echo "<br>You didn't fill in all fields. <a href='javascript:history.back()'>Go Back</a>";
} elseif($pass != $pass2) {
echo "<br>The passwords do not match. <a href='javascript:history.back()'>Go Back</a>";
} elseif($pass == $user) {
echo "<br>The username and password can't be the same. <a href='javascript:history.back()'>Go Back</a>";
} elseif(!preg_match("/^[0-9a-zA-Z]{3,15}$/i", $user)) {
echo "<br>Enter a username with only 0-9, a-z and A-Z. <a href='javascript:history.back()'>Go Back</a>";
} elseif(!preg_match("/^[0-9a-zA-Z]{3,15}$/i", $pass)) {
echo "<br>Enter a password with only 0-9, a-z and A-Z. <a href='javascript:history.back()'>Go Back</a>";
} elseif(strlen($user) < 3 || strlen($user) > 15) {
echo "<br>The username must be between 3 and 15 characters long. <a href='javascript:history.back()'>Go Back</a>";
} elseif(strlen($pass) < 3 || strlen($pass) > 15) {
echo "<br>The password must be between 3 and 15 characters long. <a href='javascript:history.back()'>Go Back</a>";
} else {
switch($dbType) {
case 'sqlsrv':
$connectionInfo = array( "Database"=>$dbName, "UID"=>$dbUser, "PWD"=>$dbPass);
$conn = sqlsrv_connect( $dbServer, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$gd = sqlsrv_query( $conn, $getuser, $guparams);
if (sqlsrv_num_rows($gd) > 0) {
echo "<br>This username is already registered. <a href='javascript:history.back()'>Go Back</a>";
} else {
$stmt = sqlsrv_query( $conn, $adduser, $auparams);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
} else {
return 1;
}
}
break;
case 'odbc08':
$conn = odbc_connect("Driver={SQL Server Native Client 10.0};Server=" . $dbServer . ";Database=" . $dbName . ";", $dbUser, $dbPass);
if( $conn === false ) {
die( print_r( odbc_error()));
}
$gd = odbc_prepare($conn, $getuser);
$gdexe = odbc_execute($gd, $guparams);
if(odbc_num_rows($gd) > 0) {
echo "<br>This username is already registered. <a href='javascript:history.back()'>Go Back</a>";
} else {
$stmt = odbc_prepare($conn, $adduser);
$execute = odbc_execute($stmt, $auparams);
if( $execute === false ) {
die( print_r( odbc_error()));
} else {
return 1;
}
}
break;
case 'odbc12':
$conn = odbc_connect("Driver={SQL Server Native Client 11.0};Server=" . $dbServer . ";Database=" . $dbName . ";", $dbUser, $dbPass);
if( $conn === false ) {
die( print_r( odbc_error()));
}
$gd = odbc_prepare($conn, $getuser);
$gdexe = odbc_execute($gd, $guparams);
if(odbc_num_rows($gd) > 0) {
echo "<br>This username is already registered. <a href='javascript:history.back()'>Go Back</a>";
} else {
$stmt = odbc_prepare($conn, $adduser);
$execute = odbc_execute($stmt, $auparams);
if( $execute === false ) {
die( print_r( odbc_error()));
} else {
return 1;
}
}
break;
}
}
}
if(isset($_POST['register'])) {
if(AddAccount($_POST['username'], $_POST['password'], $_POST['password2']) == 1) {
echo 'Account registered.';
echo '<br><strong>Username:</strong> ' . $_POST['username'];
echo '<br><strong>Password:</strong> ' . $_POST['password'];
} else {
echo '<br><br>Registration failed.';
}
} else {
# Register form, I don't provide syling.
?>
<form method="post">
<input type="text" name="username" placeholder="Username" /><br>
<input type="password" name="password" placeholder="Password" /><br>
<input type="password" name="password2" placeholder="Repeat password" /><br>
<input type="submit" name="register" value="Register" />
</form>
<?php
}
?>






