SQL server 2008 & xampp problem (INSERT INTO command)

Joined
Oct 12, 2009
Messages
33
Reaction score
10
Well, hello everybody.

I'm already bizzy for a few hours but i can't solve my problem.

I have a Xampp webserver with a Registration Page on it and a Server Statistics page.

The connection for both pages is the same, only the query is different.
For Registration: "INSERT INTO Login ([ID], [PWD], [Birth], [Type], [ExpTime]) VALUES('".$_POST["accname"]."', $cpass , '19190101', '0', '4000')"
For Statistics: "SELECT * FROM Player"

What happened, the Statistics Page shows all statistics normal as it should be. But i can't open the Registration Page, because it tells me that the connecion was lost.

The Registrationform is also 100% correct coded. What is the problem that i can't open the Registration Page??

Btw, maybe anyone knows this also:
Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 257
Code:
 => 257 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query. ) )

THANKS!!
 
Well, hello everybody.

I'm already bizzy for a few hours but i can't solve my problem.

I have a Xampp webserver with a Registration Page on it and a Server Statistics page.

The connection for both pages is the same, only the query is different.
For Registration: "INSERT INTO Login ([ID], [PWD], [Birth], [Type], [ExpTime]) VALUES('".$_POST["accname"]."', $cpass , '19190101', '0', '4000')"
For Statistics: "SELECT * FROM Player"

What happened, the Statistics Page shows all statistics normal as it should be. But i can't open the Registration Page, because it tells me that the connecion was lost.

The Registrationform is also 100% correct coded. What is the problem that i can't open the Registration Page??

Btw, maybe anyone knows this also:
Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 257
Code:
 => 257 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query. ) )

THANKS!![/quote]

Are you using mssql_connect or odbc_connect?
[php]
$username = $_POST["accname"];

$sql = "INSERT INTO
                        [Login] ([ID],[PWD],[Birth],[Type],[ExpTime],[Info])
                    VALUES
                        ('".$username."',".$password.",'19190101',0,4000,0)
                    ";
$result = odbc_exec($conn,$sql);
            if(!$result) {
                echo "Something went wrong.";
            }
[/php]

would be helpful if you would post the faulting code for the second issue.
 
Upvote 0
Are you using mssql_connect or odbc_connect?
PHP:
$username = $_POST["accname"];

$sql = "INSERT INTO
                        [Login] ([ID],[PWD],[Birth],[Type],[ExpTime],[Info])
                    VALUES
                        ('".$username."',".$password.",'19190101',0,4000,0)
                    ";
$result = odbc_exec($conn,$sql);
            if(!$result) {
                echo "Something went wrong.";
            }

would be helpful if you would post the faulting code for the second issue.
I'm using mssql connect.
But i got the same problem if i use sqlsrv.

Ill use the register.php script from bakabug's Server Tools.
 
Upvote 0
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query., SQL state 37000 in SQLExecDirect in C:\xampp\htdocs\odbc.php on line 13
Error in SQL

Using this code:
PHP:
<?php
$username = "user";
$password = "pass";

$conn=odbc_connect('kal_auth','','');
if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="INSERT INTO
                        Login (ID, PWD, Birth, Type, ExpTime, Info)
                    VALUES
                        ('".$username."','".$password."','19190101','0','4000','0')
                    ";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}

odbc_close($conn);
?>
 
Upvote 0
PHP:
$sql="INSERT INTO
                        Login (ID, PWD, Birth, Type, ExpTime, Info)
                    VALUES
                        ('".$username."',".$password.",'19190101','0','4000','0'
remove the '' around password

the " around the:
PHP:
",".$password.","
is so the statement doesn't try to literally insert $password as the password. I think the issue is that he is not using the password functions to encode the password into varbinary.


PHP:
   <?php
include 'Password.php';
$username = "user";
$password = "pass";
$password = Password::encode($password);

$conn=odbc_connect('kal_auth','','');
if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="INSERT INTO
                        Login (ID, PWD, Birth, Type, ExpTime, Info)
                    VALUES
                        ('".$username."','".$password."','19190101','0','4000','0')
                    ";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}

odbc_close($conn);
?>

I attached the Password.php file.
 

Attachments

Last edited:
Upvote 0

here's the exact code snippet by claus jorgenson's register script:
PHP:
            // encode password
            $password = Password::encode($password);
            // prepare sql
            $sql = "INSERT INTO
                        [Login] ([ID],[PWD],[Birth],[Type],[ExpTime],[Info])
                    VALUES
                        ('".$username."',".$password.",'19190101',0,4000,0)
                    ";
            // insert user
            $result = odbc_exec($conn,$sql);
            if(!$result && ($config['debug'] === true)) {
                echo odbc_errormsg($conn);
                die();
            }

and the
PHP:
$password = Password::encode($password);
was the only thing he is missing.
 
Upvote 0
ya, like i said

".$password."

instead of

'".$password."'

the content doesnt matter

I think we had some type of miscommunication here lol, the first snippet I posted had ".$password." not '".$password."'
although the second one I pasted did have it. lol, oh well.
 
Upvote 0
Oke Thanks, this one is working:
PHP:
   <?php
include 'Password.php';
$username = "user";
$password = "pass";
$password = Password::encode($password);

$conn=odbc_connect('kal_auth','','');
if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="INSERT INTO
                        Login (ID, PWD, Birth, Type, ExpTime, Info)
                    VALUES
                        ('".$username."',".$password.",'19190101','0','4000','0')
                    ";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}

odbc_close($conn);
?>

Now i'm gonna try if it still works with a form...

---------- Post added at 09:03 AM ---------- Previous post was at 08:45 AM ----------

Hmm, now getting this error:
Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\odbc.php on line 3

With this codes:
PHP:
<?php
include 'Password.php';
$username = $_POST['username'];
$password = $_POST['password'];
$password = Password::encode($password);

$conn=odbc_connect('kal_auth','','');
if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="INSERT INTO
                        Login (ID, PWD, Birth, Type, ExpTime, Info)
                    VALUES
                        ('".$username."',".$password.",'19190101','0','4000','0')
                    ";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}

odbc_close($conn);
?>

With this form:
PHP:
<form action="odbc.php" method="post">
  <p>Register Account: </p>
  <p>
    <input name="username" type="text" id="username" value="ID" maxlength="8">
    <input name="password" type="password" id="password" value="Password" maxlength="10">
    <input type="submit" name="Submit" value="Create">
  </p>
</form>

I dont understand why it's unexpected? Normally this should work right?

---------- Post added at 09:22 AM ---------- Previous post was at 09:03 AM ----------

What the f*** ????

WORKING:
PHP:
<?php
include 'Password.php';
$username = $_POST['username'];
$password = $_POST['password'];
$password = Password::encode($password);

NOT WORKING:
PHP:
<?php
include 'Password.php';
$username = $_POST['username'];
$password = $_POST['password'];
$password = Password::encode($password);

What is wrong ???? xD
 
Upvote 0
Back