PHP插入表数据代码不将数据插入MSSQL表[关闭]

PHP插入表数据代码不将数据插入MSSQL表[关闭]

问题描述:

I am trying to run a PHP page that should insert a username and password into my MSSQL table "users". When I run the page the only thing that appears is the errors:

Warning: mssql_query() [function.mssql-query]: message: 'md5' is not a recognized built-in function name. (severity 15) in D:\Hostins0\html\insertadminaccount.php on line 10

Warning: mssql_query() [function.mssql-query]: Query failed in D:\Hostinstml\insertadminaccount.php on line 10
'md5' is not a recognized built-in function name.

Here is my full PHP page code:

<?php
$conn=mssql_connect('sm','Gaer','Ra1!');
mssql_select_db('Gser',$conn);
if(! $conn )
{
  die('Could not connect: ' . mssql_get_last_message());
}
   $sqla = "INSERT INTO users (username, password)
VALUES ('rob_dewar01', " . md5 ('KingDozer') . ")";
mssql_query($sqla, $conn) or die(mssql_get_last_message());

if (!mssql_query) {
    // The query has failed, print a nice error message
    // using mssql_get_last_message()
    die('MSSQL error: ' . mssql_get_last_message());
}

mssql_close($conn);
?>

Thank you for any help. All help is appreciated.

MSSQL doesn't have a direct md5 function (you can convert it as demonstrated here). You need to use it through PHP like so:

$sqla = "INSERT INTO users (username, password)
VALUES ('rob_dewar01', '" . md5('KingDozer') . "')";

Also, md5 is not secure. Look into using prepared statements.

See the Secure hash and salt for PHP passwords question for more information about hashing passwords in PHP.