我有一个将数据添加到 MySQL DB 的 PHP 表单,我现在必须转换该 PHP 代码,以便它可以在 MSSQL DB 上工作。PHP 在服务器上运行良好。
这是我到目前为止所拥有的,基本上我将所有 WAS mysql_ 更改为 mssql_ 但它不起作用。我有一条我没有显示的行,它调用了一个连接到数据库的配置文件,我也没有显示 HTML 表单,除非你需要它。
<?php
if (isset($_POST['vendor_id'])) { //Check for a field that is mandatory to do the inserted
$vendor = mssql_escape_string($_POST['vendor_id']);
$name = mssql_escape_string($_POST['name_id']);
$version = mssql_escape_string($_POST['version']);
$serial = (!empty($_POST['serial'])) ? $_POST['serial'] : 'NULL';
$productkey = (!empty($_POST['productkey'])) ? $_POST['productkey'] : 'NULL';
$department = mssql_escape_string($_POST['department']);
$owner = mssql_escape_string($_POST['owner']);
$computer = (!empty($_POST['computer'])) ? $_POST['computer'] : 'NULL';
$comments = (!empty($_POST['comments'])) ? $_POST['comments'] : 'NULL';
$acquired = (!empty($_POST['acquired'])) ? $_POST['acquired'] : 'NULL';
$retired = mssql_escape_string($_POST['retired']);
$sql = "INSERT INTO dbo.keylist_detail (vendor_id,name_id,version,Serial,ProductKey,department_ID,owner,computer,Comments,acquired,retired)
VALUES (''$vendor','$name','$version',$serial','$productkey','$department','$owner','$computer','$comments','$acquired','$retired'')";
mssql_query($SQL);
if (mssql_query($sql)) {
echo '<strong><em>Your data has been submitted</em></strong><br /><br />';
} else {
echo '<p>Error adding submitted info: ' . mssql_error(). '</p>';
}
}
?>