Registration.php

05/28/2018 00:48 tiaguim#1
After countless hours of searching and searching and searching, i came up with this scrip to try to make a php5.6 -> SQL server 2000 connection, it actualy works doesn't show any error but...Doens't send data to the actual database

PHP Code:
<?php
$awnser 
"nuncavida";
$password2 "12345678";
$question "Ratos";
$mail "exemplohotmail";
$accountN "09101410275852";
$database "account";
$user "sa";
$password"1234";
$server "localhost";
$conn odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;"$user$password);
if(
$conn){
      die(
print_r(sqlsrv_errors(), true));
}


$db_selected mysql_select_db($database$conn);

if (!
$db_selected) {
    die(
'Can\'t use ' .$database': ' .mysql_error());
}

$value $_POST['input1'];

$dk_time=strftime("%y%m%d%H%M%S");
list(
$usec1$sec1) = explode(" ",microtime());
$dk_user_no=$dk_time.substr($usec1,2,2);


mssql_query("Insert Into [TBL_USER] Values ('09101410275532', 'tiaguim32', '12345', 'wefew', 'wefewefw', 'wefeww', '25.66.7.153')");


mysql_close();
?>
Do you guys know any way of making this work? It's making me crazy! Cause the connection works, then? Why it doens't transfer the data to the database colums?

Thanks :D
05/28/2018 00:51 ZKDev#2
@[Only registered and activated users can see links. Click Here To Register...]

PHP Code:
INSERT INTO [TBL_USER] (column_1column_2column_3column_4column_5column_6column_7VALUES (
'09101410275532',
'tiaguim32',
'12345',
'wefew',
'wefewefw',
'wefeww',
'25.66.7.153'
); 
You cannot simply insert the values you gotta declare every single column at first.
Even tho Im not sure if your tablename may include '[' or ']' better remove 'em.
05/28/2018 00:58 tiaguim#3
Ohhh, also already tryed! Didn't work...

PHP Code:
<?php
$awnser 
"nuncavida";
$password2 "12345678";
$question "Ratos";
$mail "exemplohotmail";
$accountN "09101410275852";
$database "account";
$user "sa";
$password"1234";
$server "localhost";
$conn odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;"$user$password);

if(
$conn){
      die(
print_r(sqlsrv_errors(), true));
}


$db_selected mysql_select_db($database$conn);

if (!
$db_selected) {
    die(
'Can\'t use ' .$database': ' .mysql_error());
}

$value $_POST['input1'];

$dk_time=strftime("%y%m%d%H%M%S");
list(
$usec1$sec1) = explode(" ",microtime());
$dk_user_no=$dk_time.substr($usec1,2,2);


mssql_query("Insert Into TBL_USER(user_no,user_id,user_pwd,user_mail,user_answer,user_question,IP)  Values ('09101410275532', 'tiaguim32', '12345', 'wefew', 'wefewefw', 'wefeww', '25.66.7.153')");


mysql_close();
?>
It gives a blank page, it means it worked, but when you go to the tbl_user, you don't see the stuff you entered


I know the script is sucky sucky as shit, but it's only for the purpose of making it work xD
05/28/2018 01:07 iMostLiked#4
Use [Only registered and activated users can see links. Click Here To Register...] class.

Example:

PHP Code:
include('MysqliDb.php');
$db = new MysqliDb ('host''username''password''database');

$db->insert('TBL_USER', array(
    
'user_no' => '09101410275532',
    
'...' => '...'
)); 
It's pretty easy, clean and secure since it uses prepared statements. :)
05/28/2018 01:14 tiaguim#5
Quote:
Originally Posted by iMostLiked View Post
Use [Only registered and activated users can see links. Click Here To Register...] class.

Example:

PHP Code:
include('MysqliDb.php');
$db = new MysqliDb ('host''username''password''database');

$db->insert('TBL_USER', array(
    
'user_no' => '09101410275532',
    
'...' => '...'
)); 
It's pretty easy, clean and secure since it uses prepared statements. :)
Hello! Where do i put the "MysqliDb.php" file? So i can used it in the script?
05/28/2018 01:17 iMostLiked#6
Quote:
Originally Posted by tiaguim View Post
Hello! Where do i put the "MysqliDb.php" file? So i can used it in the script?
Put it next to your script in the same directory.
05/28/2018 01:23 tiaguim#7
CODE

PHP Code:
<?php
include('MysqliDb.php');
$db = new MysqliDb ('localhost''root''''account');

$db->insert('TBL_USER', array(
    
'user_no' => '09101410275532',
    
'user_id' => 'tiaguim32',
    
'user_pwd' => '1234567',
    
'user_mail' => 'defdewfrwef',
    
'user_answer' => 'fdwefrfwefrwe',
    
'user_question' => 'efdwefewfewf',
    
'IP' => '1523615'
)); 
?>
Result:
Warning: mysqli::mysqli(): (HY000/1049): Unknown database 'account' in C:\xampp\htdocs\MysqliDb.php on line 295

Fatal error: Uncaught exception 'Exception' with message 'Connect Error 1049: Unknown database 'account'' in C:\xampp\htdocs\MysqliDb.php:298 Stack trace: #0 C:\xampp\htdocs\MysqliDb.php(377): MysqliDb->connect('default') #1 C:\xampp\htdocs\MysqliDb.php(1908): MysqliDb->mysqli() #2 C:\xampp\htdocs\MysqliDb.php(1519): MysqliDb->_prepareQuery() #3 C:\xampp\htdocs\MysqliDb.php(1459): MysqliDb->_buildQuery(NULL, Array) #4 C:\xampp\htdocs\MysqliDb.php(765): MysqliDb->_buildInsert('TBL_USER', Array, 'INSERT') #5 C:\xampp\htdocs\Processo2.php(13): MysqliDb->insert('TBL_USER', Array) #6 {main} thrown in C:\xampp\htdocs\MysqliDb.php on line 298

Hmmm, has my knowledge reach, this is going to the datebases os "XAMPP" and not to the databases of SQL server, so thats why it doens't recognize the "account" database, cause it doesn't exist in the "Myphpadmin" stuff xD

Correct me if im wrong



If in the "account" stuff i put one of the myphpadmin default datebases, i get this


Fatal error: Uncaught exception 'Exception' with message 'Table 'test.tbl_user' doesn't exist query: INSERT INTO TBL_USER (`user_no`, `user_id`, `user_pwd`, `user_mail`, `user_answer`, `user_question`, `IP`) VALUES (?, ?, ?, ?, ?, ?, ?)' in C:\xampp\htdocs\MysqliDb.php:1926 Stack trace: #0 C:\xampp\htdocs\MysqliDb.php(1519): MysqliDb->_prepareQuery() #1 C:\xampp\htdocs\MysqliDb.php(1459): MysqliDb->_buildQuery(NULL, Array) #2 C:\xampp\htdocs\MysqliDb.php(765): MysqliDb->_buildInsert('TBL_USER', Array, 'INSERT') #3 C:\xampp\htdocs\Processo2.php(13): MysqliDb->insert('TBL_USER', Array) #4 {main} thrown in C:\xampp\htdocs\MysqliDb.php on line 1926
05/28/2018 01:28 iMostLiked#8
Quote:
Originally Posted by tiaguim View Post
CODE

PHP Code:
<?php
include('MysqliDb.php');
$db = new MysqliDb ('localhost''root''''account');

$db->insert('TBL_USER', array(
    
'user_no' => '09101410275532',
    
'user_id' => 'tiaguim32',
    
'user_pwd' => '1234567',
    
'user_mail' => 'defdewfrwef',
    
'user_answer' => 'fdwefrfwefrwe',
    
'user_question' => 'efdwefewfewf',
    
'IP' => '1523615'
)); 
?>
Result:
Warning: mysqli::mysqli(): (HY000/1049): Unknown database 'account' in C:\xampp\htdocs\MysqliDb.php on line 295

Fatal error: Uncaught exception 'Exception' with message 'Connect Error 1049: Unknown database 'account'' in C:\xampp\htdocs\MysqliDb.php:298 Stack trace: #0 C:\xampp\htdocs\MysqliDb.php(377): MysqliDb->connect('default') #1 C:\xampp\htdocs\MysqliDb.php(1908): MysqliDb->mysqli() #2 C:\xampp\htdocs\MysqliDb.php(1519): MysqliDb->_prepareQuery() #3 C:\xampp\htdocs\MysqliDb.php(1459): MysqliDb->_buildQuery(NULL, Array) #4 C:\xampp\htdocs\MysqliDb.php(765): MysqliDb->_buildInsert('TBL_USER', Array, 'INSERT') #5 C:\xampp\htdocs\Processo2.php(13): MysqliDb->insert('TBL_USER', Array) #6 {main} thrown in C:\xampp\htdocs\MysqliDb.php on line 298

Hmmm, has my knowledge reach, this is going to the datebases os "XAMPP" and not to the databases of SQL server, so thats why it doens't recognize the "account" database, cause it doesn't exist in the "Myphpadmin" stuff xD

Correct me if im wrong
You didn't even use the credentials you used above for user and password.
It should work if everything is filled in properly, since it's nothing else you did above, only in a cleaner and easier way.
05/28/2018 01:31 tiaguim#9
Quote:
Originally Posted by iMostLiked View Post
You didn't even use the credentials you used above for user and password.
It should work if everything is filled in properly, since it's nothing else you did above, only in a cleaner and easier way.
I had to change the credentials because they don't exist in myphpadmin...if i want to use those credentials i've to create a new user, and them it will give the same error saying that the table doesn't exist xD

PHP Code:
<?php
include('MysqliDb.php');
$db = new MysqliDb ('localhost''sa''1234''account');

$db->insert('TBL_USER', array(
    
'user_no' => '09101410275532',
    
'user_id' => 'tiaguim32',
    
'user_pwd' => '1234567',
    
'user_mail' => 'defdewfrwef',
    
'user_answer' => 'fdwefrfwefrwe',
    
'user_question' => 'efdwefewfewf',
    
'IP' => '1523615'
)); 
?>

Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'sa'@'localhost' (using password: YES) in C:\xampp\htdocs\MysqliDb.php on line 295

Fatal error: Uncaught exception 'Exception' with message 'Connect Error 1045: Access denied for user 'sa'@'localhost' (using password: YES)' in C:\xampp\htdocs\MysqliDb.php:298 Stack trace: #0 C:\xampp\htdocs\MysqliDb.php(377): MysqliDb->connect('default') #1 C:\xampp\htdocs\MysqliDb.php(1908): MysqliDb->mysqli() #2 C:\xampp\htdocs\MysqliDb.php(1519): MysqliDb->_prepareQuery() #3 C:\xampp\htdocs\MysqliDb.php(1459): MysqliDb->_buildQuery(NULL, Array) #4 C:\xampp\htdocs\MysqliDb.php(765): MysqliDb->_buildInsert('TBL_USER', Array, 'INSERT') #5 C:\xampp\htdocs\Processo2.php(13): MysqliDb->insert('TBL_USER', Array) #6 {main} thrown in C:\xampp\htdocs\MysqliDb.php on line 298
05/28/2018 01:39 iMostLiked#10
Quote:
Originally Posted by tiaguim View Post
I had to change the credentials because they don't exist in myphpadmin...if i want to use those credentials i've to create a new user, and them it will give the same error saying that the table doesn't exist xD

PHP Code:
<?php
include('MysqliDb.php');
$db = new MysqliDb ('localhost''sa''1234''account');

$db->insert('TBL_USER', array(
    
'user_no' => '09101410275532',
    
'user_id' => 'tiaguim32',
    
'user_pwd' => '1234567',
    
'user_mail' => 'defdewfrwef',
    
'user_answer' => 'fdwefrfwefrwe',
    
'user_question' => 'efdwefewfewf',
    
'IP' => '1523615'
)); 
?>

Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'sa'@'localhost' (using password: YES) in C:\xampp\htdocs\MysqliDb.php on line 295

Fatal error: Uncaught exception 'Exception' with message 'Connect Error 1045: Access denied for user 'sa'@'localhost' (using password: YES)' in C:\xampp\htdocs\MysqliDb.php:298 Stack trace: #0 C:\xampp\htdocs\MysqliDb.php(377): MysqliDb->connect('default') #1 C:\xampp\htdocs\MysqliDb.php(1908): MysqliDb->mysqli() #2 C:\xampp\htdocs\MysqliDb.php(1519): MysqliDb->_prepareQuery() #3 C:\xampp\htdocs\MysqliDb.php(1459): MysqliDb->_buildQuery(NULL, Array) #4 C:\xampp\htdocs\MysqliDb.php(765): MysqliDb->_buildInsert('TBL_USER', Array, 'INSERT') #5 C:\xampp\htdocs\Processo2.php(13): MysqliDb->insert('TBL_USER', Array) #6 {main} thrown in C:\xampp\htdocs\MysqliDb.php on line 298
This is an error on the side of your server, check everything again. Are you sure that this user has full rights on this database? Is the password correct?
The script seems to work properly.
05/28/2018 01:42 tiaguim#11
Quote:
Originally Posted by iMostLiked View Post
This is an error on the side of your server, check everything again. Are you sure that this user has full rights on this database? Is the password correct?
The script seems to work properly.
Even if not, the "Root" user should work right? Since by default is a super user with all rights over the datebase right


In the other script if i use root as user, gives this error

Warning: odbc_connect(): SQL error: [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'root'., SQL state 28000 in SQLConnect in C:\xampp\htdocs\Processo.php on line 11

Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\Processo.php on line 18
Can't use account:

Pretty messed up ham? XDDDD



If i run the querry on the SQL server querry stuff, it goes normal...but theres is no point there...
06/09/2018 23:42 Enigmacpp#12
Pretty simple.
Download sqlsrv microsoft driver (but check if you have thread safe or not) and add your info right there.
I can give you an example.

Quote:
/*
|--------------------------------------------------------------------------
| Mssql (SQL Server)
|--------------------------------------------------------------------------
|
| We do not recommend sa user as default user and add an firewall exception for your IP if you are
| hosting this website outside the machine where the server is being hosted.
| Holds the dekaron sql server information to make the changes in the
| game emulator tables
| Here are some steps to follow to make sure sqlsrv is loaded and this
| functionallity do not break!
| 1- Check the phpinfo() and check if we are in thread_safety or not
| 2- Download MSSQL Drivers [Only registered and activated users can see links. Click Here To Register...] according to the thread_safety
| 3- Extract to php libs the choosed dll example: php_sqlsrv54_ts.dll
| 4- Modify the php.ini and add this new extension like extesion=php_sqlsrv54_ts.dll
| 5- Enable SQL Server to listen in specific ports so we go to SQL Configuration Manager/Protocols/Properties and make sure it's enabled and which
| port it is listening
| 6- Restart both services (mysqld) and (mssql)
|
| P.S: In case you get unable to load function or invalid win32 dll you must change the architecture to x86 or vice versa
|
*/
$db['mssql'] = array(
'hostname' => '127.0.0.1',
'port' => 1433,
'username' => 'sa',
'password' => '1234',
'database' => 'account',
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'autoinit' => TRUE
);
That's my config for my custom query builder class but just you have an idea of the basic things you need like user,host,port,db and pwd and so after you get an array or whatever to store that data you do a basic connection. (Make sure your mssql allow external connections and you have permission on that user)

[Only registered and activated users can see links. Click Here To Register...]
06/10/2018 00:38 tiaguim#13
Thanks for the explanation! I came up with this working code!

PHP Code:
 <?php
$serverName 
"(local)";
$connectionInfo = array( "Database"=>"account""UID"=>"tiaguim""PWD"=>"1234" );
$connectionInfo2 = array( "Database"=>"cash""UID"=>"tiaguim""PWD"=>"1234" );
$conn sqlsrv_connect$serverName$connectionInfo);
$conn2 sqlsrv_connect$serverName$connectionInfo2);
if( 
$conn === false ) {
     die( 
print_rsqlsrv_errors(), true));
}
//Random numero do ID de utilizador
$dk_time=strftime("%y%m%d%H%M%S");
list(
$usec1$sec1) = explode(" ",microtime());
$dk_user_no=$dk_time.substr($usec1,2,2);

//Pegar valores do index
$UsuarioID $_POST['input1'];
$Password md5($_POST['input2']);
$Mail $_POST['input3'];
$Pergunt $_POST['input4'];
$Respost $_POST['input5'];

//Botão Pressionado
if(isset($_POST['register'])){
    
$Loginsql "select user_id from Tbl_user where user_id='$UsuarioID'";
$params2 = array();
$options =  array( "Scrollable" => "buffered" );


$qLogin sqlsrv_query($conn$Loginsql$params2$options);
$rLogin sqlsrv_num_rows($qLogin);


$Mailsql "select user_mail from Tbl_user where user_mail='$Mail'";

$qEmail sqlsrv_query($conn$Mailsql$params2$options);
$rEmail sqlsrv_num_rows($qEmail);

if(empty(
$UsuarioID) || empty($Password) || empty($Mail) || empty($Pergunt) || empty($Respost)) {
echo 
"Preencha todos os campos corretamente, volte para a página <a href='http://25.81.112.243/Ryudekaron.html'> inicial <a/>";
}
elseif(
$rLogin >= 1){
die(
"Esse usuario já existe, volte para a página <a href='http://25.81.112.243/Ryudekaron.html'> inicial <a/>");
}
elseif(
$rEmail >= 1){
die(
"Esse email já existe, volte para a página <a href='http://25.81.112.243/Ryudekaron.html'> inicial <a/>");
}
else{

//Dia hora data
$dia = (strftime("%x %X"));



//Tbl_user
$sql "INSERT INTO Tbl_user (user_no, user_id, user_pwd, user_mail, user_answer, user_question, IP) VALUES (?,?,?,?,?,?,?)";
$params = array($dk_user_no$UsuarioID$Password$Mail$Respost$Perguntnull);

$stmt sqlsrv_query$conn$sql$params);
if( 
$stmt === false ) {
     die( 
print_rsqlsrv_errors(), true));
}

//USER_PROFILE
$sql2 "INSERT INTO USER_PROFILE (user_no, user_id, user_pwd, resident_no, user_type, login_flag, login_tag, ipt_time, login_time, logout_time, user_ip_addr, server_id) VALUES (?,?,?,?,?,?,?,?,?,?,CAST('?' AS VARBINARY(4)),?)";
$params2 = array($dk_user_no$UsuarioID$Password"801011000000""1""0""Y"$dianullnullnull"000");

$stmt2 sqlsrv_query$conn$sql2$params2);
if( 
$stmt2 === false) {
    die( 
print_rsqlsrv_errors(), true));
}

//user_cash
$sql3 "INSERT INTO user_cash (id, user_no, group_id, amount, free_amount) VALUES (?,?,?,?,?)";
$params3 = array($dk_user_no$dk_user_no,"01","10000","0" );

$stmt3 sqlsrv_query$conn2$sql3$params3);
if (
$stmt3 === false) {
    die( 
print_rsqlsrv_errors(), true));
}
Echo 
"Sua conta foi registada com sucesso!";
}
}
?>
Well, it works xD