Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-01-2012, 03:03 AM   PM User | #1
teemo87
New Coder

 
Join Date: Oct 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
teemo87 is an unknown quantity at this point
Simple Help Reg page connected to mssql DB

Hey Friends i need a big favor i paid for a dedicated server with out knowing that the server i was going to host required a registration page.

The Server is done in MsSql
All i really need is something simpler then this and how to work it?

Gonna get killed for posting another link but i didn't wanna post the full code..

Thanks in advance

http://forum.ragezone.com/f772/reg-s...op-ppl-813662/
teemo87 is offline   Reply With Quote
Old 10-01-2012, 03:23 AM   PM User | #2
teemo87
New Coder

 
Join Date: Oct 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
teemo87 is an unknown quantity at this point
I've got this far


http://cdandl.us/register.htm
teemo87 is offline   Reply With Quote
Old 10-01-2012, 06:06 AM   PM User | #3
teemo87
New Coder

 
Join Date: Oct 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
teemo87 is an unknown quantity at this point
bump??
teemo87 is offline   Reply With Quote
Old 10-01-2012, 02:37 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I don't understand what you mean by "host required a registration page". If you've got a dedicated or a VPS, then there's really no requirement for you to install anything on it.

Post the code here, make sure you surround it with [php][/php] tags to preserve the formatting. Its too hard to read there.
Then you need to tell us what the actual issue is. Nobody will rewrite the code or convert the database engine or anything like that, but if you have an error then we can help you fix that.
Fou-Lu is offline   Reply With Quote
Old 10-01-2012, 11:56 PM   PM User | #5
teemo87
New Coder

 
Join Date: Oct 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
teemo87 is an unknown quantity at this point
Well im hosting a game server on mssql.
To link from a Registration page that sends an account name and password people choose

PHP Code:

<?php

$cfg
['sql_host'] = "CUSTOMER-PC\SQLEXPRESS";
$cfg['sql_user'] = "Myusername";
$cfg['sql_pass'] = "Mypassword";
$cfg['sql_db'] = "SRO_VT_Account";


$sqlLink mssql_connect($cfg[sql_host],$cfg[sql_user],$cfg[sql_pass]);
    if(!
$sqlLink) die("MSSQL server is not accessable, why should we try to select database ?");
        else
        {
            
mssql_select_db($cfg[sql_db],$sqlLink);
        }
?>
teemo87 is offline   Reply With Quote
Old 10-02-2012, 12:10 AM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Okay, don't use mssql at all. The package is old, and I don't believe they intend to keep it around much longer. I'd recommend for a concrete implementation that you use SQLSRV.

Other than that, you didn't really specify what you are needing to do / the error you have with the above. Although lacking the mssql extension wouldn't surprise me which is why I suggested looking into the SQLSRV. You can also look into PDO, but I'm not sure what the SQLServer drivers are like for support on it.
Fou-Lu is offline   Reply With Quote
Old 10-02-2012, 12:21 AM   PM User | #7
teemo87
New Coder

 
Join Date: Oct 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
teemo87 is an unknown quantity at this point
That version of sql is the only version that will run the server files correctly and i keep getting an error of not connecting to database
teemo87 is offline   Reply With Quote
Old 10-02-2012, 12:29 AM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Change this:
PHP Code:
    if(!$sqlLink) die("MSSQL server is not accessable, why should we try to select database ?"); 
To this:
PHP Code:
    if(!$sqlLink) die("Failed to connect: " mssql_get_last_message()); 
I assume you can fetch an error off of a mssql_connect. If it produces no cause for the failed to connect message, you'll need to check your sqlserver logs.
Fou-Lu is offline   Reply With Quote
Old 10-02-2012, 01:09 AM   PM User | #9
teemo87
New Coder

 
Join Date: Oct 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
teemo87 is an unknown quantity at this point
Always get this error

Fatal error: Call to undefined function mssql_connect() in D:\Hosting\9503144\html\_inc\config.php on line 9
teemo87 is offline   Reply With Quote
Old 10-02-2012, 01:12 AM   PM User | #10
teemo87
New Coder

 
Join Date: Oct 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
teemo87 is an unknown quantity at this point
Main code
PHP Code:
 <?php
/* Simple registration page for silkroad server, by Chernobyl
 * Settings are at _inc/config.php
 * If you get an mssql connection error, while defining totally correct data
 * Just use older ntwdblib.dll for your webserver
*/
require_once('_inc/security.class.php');
require_once(
'_inc/config.php');

if(!isset(
$_POST['submit']))
    {
        echo 
"<table border='1'>
        <form method='post'>
        <td>Username</td><td><input type='text' name='username' maxlength='16'></td><tr/>
        <td>Password[1]</td><td><input type='password' name='pw1' maxlength='32'></td><tr/>
        <td>Password[2]</td><td><input type='password' name='pw2' maxlength='32'></td><tr/>
        <td></td><td><input type='submit' name='submit' value='Register'></td>
        </form>
                </table>"
;
    }
    else
    {
                if(
is_array($user) == true$err[] = "Username is array, n00p";
        if(
is_array($pass1) == true$err[] = "Pw1 is array, n00p";
        if(
is_array($pass2) == true$err[] = "Pw2 is array, n00p";
        if(
strlen($_POST['username']) < 3$msg[] = "Username too short";
        if(
strlen($_POST['username']) > 16)$msg[] = "Username too long";
        if(
strlen($_POST['pw1']) < 6$msg[] = "Password [1] too short";
        if(
strlen($_POST['pw1']) > 32)$msg[] = "Password [1] too long";
        if(
strlen($_POST['pw2']) < 6$msg[] = "Password [2] too short";
        if(
strlen($_POST['pw']) > 32$msg[] = "Password [2] too long";
        if(
$_POST['pw1'] != $_POST['pw2']) $msg[] = "Passwords are not the same";
        
            
$sec = new security();
            
            if(
$sec->is_secure($_POST['username']) == false$msg[] = "Username contains forbidden symbols";
            if(
$sec->is_secure($_POST['pw1']) == false$msg[] = "Password [1] contains forbidden symbols";
            if(
$sec->is_secure($_POST['pw2']) == false$msg[] = "Password [2] contains forbidden symbols";
            
            if(
count($msg) > 0)
                {
                    for(
$i 0$i count($msg); $i++)
                        {
                            echo 
$msg[$i]."<br/>";
                        }
                        return;
                }
                else
                    {
                        
//checking damn mssql stuff
                        
$accountExists mssql_num_rows(mssql_query("select StrUserID from TB_User where StrUserID='$_POST[username]'"));
                            if(
$accountExists 0) echo "Account with such username already exists<br/>";
                                else
                                {
                                    
$pwd md5($_POST['pw1']);
                                    
mssql_query("insert into TB_User(StrUserID,password,sec_primary,sec_content) values('$_POST[username]','$pwd','3','3')");
                                        echo 
"Account successfully created<br/>";
                                }
                    }

    }
?>


_inc/security.class.php
PHP Code:
 <?php
class security
{
function 
is_secure($string)
            {
            
$pattern "#[^a-zA-Z0-9_\-]#";
                if(
preg_match($pattern,$string)==true)return false;
                        else
                        return 
true;
                }            
}
?>




Code you told me to fix
_inc/config
PHP Code:
<?php

$cfg
['sql_host'] = "CUSTOMER-PC\SQLEXPRESS";
$cfg['sql_user'] = "*******";
$cfg['sql_pass'] = "*******";
$cfg['sql_db'] = "SRO_VT_Account";


$sqlLink mssql_connect($cfg[sql_host],$cfg[sql_user],$cfg[sql_pass]);
    if(!
$sqlLink) die("Failed to connect: " mssql_get_last_message());  
        else
        {
            
mssql_select_db($cfg[sql_db],$sqlLink);
        }
?>
teemo87 is offline   Reply With Quote
Old 10-02-2012, 01:13 AM   PM User | #11
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by teemo87 View Post
Always get this error

Fatal error: Call to undefined function mssql_connect() in D:\Hosting\9503144\html\_inc\config.php on line 9
You don't have mssql installed. You'll need to consult the documentation here for installing it. The requirements section is the most important part of this package; installation on windows is a simple matter of uncommenting the line in php.ini to enable it, but you require the dll's on the system path to run it.
Fou-Lu is offline   Reply With Quote
Old 10-02-2012, 01:16 AM   PM User | #12
teemo87
New Coder

 
Join Date: Oct 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
teemo87 is an unknown quantity at this point
I have mssql installed on my server pc that is what my server is running off of.
teemo87 is offline   Reply With Quote
Old 10-02-2012, 01:21 AM   PM User | #13
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by teemo87 View Post
I have mssql installed on my server pc that is what my server is running off of.
The error says you do not have mssql extension installed.
You may have SQLServer installed as a database, but you need to configure PHP to use mssql extension.
Fou-Lu is offline   Reply With Quote
Old 10-02-2012, 01:23 AM   PM User | #14
teemo87
New Coder

 
Join Date: Oct 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
teemo87 is an unknown quantity at this point
Thanks for the help so far ill test and see what i can do
thanks again
teemo87 is offline   Reply With Quote
Old 10-02-2012, 01:41 AM   PM User | #15
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by teemo87 View Post
Thanks for the help so far ill test and see what i can do
thanks again
Your welcome.
Interesting note I hadn't seen:
Quote:
This extension is not available anymore on Windows with PHP 5.3 or later.
According to this, you need to use 5.2x or older version of PHP in order to use mssql extension. Otherwise you'll need to rewrite the code in PDO or SQLSrv (even odbc would work). I knew it was going away, but I didn't think it was actually gone.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:54 PM.


Advertisement
Log in to turn off these ads.