I'm starting to learn a bit of programming, and I try to make a record that connects to a sql manager studio 2008 r2 database. Everything is fine in terms of the local environment, the registry works just like the sql, but as soon as I upload the registry to a web host, it stops working, I get a connection error and I do not understand why it can be, I have reviewed everything what has occurred to me, port 1433, browser, ip's firewall, ports of the pc, router ... For my part I ran out of ideas ... If someone can help me please ^^ The record had it in odbc, but they told me that this was an error and now I am using mssql, if I can choose, I prefer odbc that I have everything done in that environment.
Thanks for reading, a pleasure to enter this community. db.config.php
<?php
$dbHost = 'localhost';
$dbUser = 'test';
$dbPass = 'test123';
$GLOBALS['dbConn'] = @odbc_connect("Driver={SQL Server};Server={$GLOBALS['dbHost']};",$GLOBALS['dbUser'],$GLOBALS['dbPass']) or die('Database Connection Error!');
if(!$GLOBALS['dbConn']){
exit("Connection failed:".odbc_errormsg());
}
?>
register.php
<?php
require_once('db.config.php');
$user_ip = $_SERVER['REMOTE_ADDR'];
$username = isset($_POST['username']) ? trim($_POST['username']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
$password2 = isset($_POST['password2']) ? trim($_POST['password2']) : '';
$nombre = isset($_POST['nombre']) ? trim($_POST['nombre']) : '';
$apellidos = isset($_POST['apellidos']) ? trim($_POST['apellidos']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
$patron = isset($_POST['patron']) ? trim($_POST['patron']) : '';
$errors = array();
$success = false;
if(isset($_POST) && !empty($_POST)){
if(empty($username)){
$errors[] = 'Please provide a user name.';
}else if(strlen($username) < 3 || strlen($username) > 16){
$errors[] = 'User name must be between 3 and 16 characters in length.';
}else if(ctype_alnum($username) === false){
$errors[] = 'User name must consist of numbers and letters only.';
}else{
// Check if username already exists in the database.
$sql = "SELECT UserID FROM PS_UserData.dbo.Users_Master WHERE UserID = ?";
$stmt = odbc_prepare($GLOBALS['dbConn'],$sql);
$args = array($username);
if(!odbc_execute($stmt,$args)){
$errors[] = 'Failed to determine if this username already exists in the database.';
}elseif($row = odbc_fetch_array($stmt)){
$errors[] = 'User name already exists, please choose a different user name.';
}
}
if(empty($password)){
$errors[] = 'Please provide a password.';
}else if(strlen($password) < 3 || strlen($password) > 16){
$errors[] = 'Password must be between 3 and 16 characters in length.';
}else if($password != $password2){
$errors[] = 'Passwords do not match.';
}
if(count($errors) == 0){
$sql = "INSERT INTO PS_UserData.dbo.Users_Master
(UserID,Pw,JoinDate,Admin,AdminLevel,UseQueue,Status,Leave,LeaveDate,UserType,Point,EnPassword,UserIp,nombre,apellidos,email,patron)
VALUES (?,?,GETDATE(),0,0,0,0,0,GETDATE(),'N',0,'',?,?,?,?,?)";
$stmt = odbc_prepare($GLOBALS['dbConn'],$sql);
$args = array($username,$password,$user_ip,$nombre,$apellidos,$email,$patron);
if(odbc_execute($stmt,$args)){
$success = htmlentities("Account {$username} successfully created!");
}else{
$errors[] = 'Failed to create a new account, please try again later';
}
}
}
if($success === false){
require_once('register.view.php');
}else{
require_once('success.view.php');
}
?>