我正在尝试根据表单的输入将记录移动到数据库,但似乎遇到了问题。我已经尝试过以下但它没有在数据库上执行命令。它需要读取一个值作为决策,并根据决定进行查询。任何人都可以在这里发现问题吗?我在SQL Server中运行了查询,但它确实有效。
HTML表单代码:
<!--Other Form-->
<center>
<div class="container">
<form action="dLG.php" onsubmit="return confirm('Are you sure you wish to delete ?');">
<div class="row">
<div class="col-25">
<label for="License Group ID">Enter the License Group ID that you wish to delete</label>
</div>
<div class="col-75">
<input type="number" name="LicenseGroupID" placeholder="LicenseGroupID">
</div>
</div>
<br>
<div class="row">
<input type="submit" value="Delete License Group">
</div>
</form>
</div>
</center>
php:
<html>
<?php
$serverName = "x";
$options = array( "UID" => "x", "PWD" => "x", "Database" => "x");
$conn = sqlsrv_connect($serverName, $options);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
$License_Group_ID = $_POST['LicenseGroupID'];
$query = "DELETE FROM dbo.tbl_license_group
OUTPUT
deleted.License_Group_ID,
deleted.Vendor_Name,
deleted.License_Version,
deleted.Edition,
deleted.Operating_System,
deleted.Quantity
INTO dbo.tbl_license_group_delete(License_Group_ID, Vendor_Name, License_Version,Edition,Quantity)
WHERE License_Group_ID = '$License_Group_ID'; " ;
$params1 = array($License_Group_ID);
$result = sqlsrv_query($conn,$query,$params1);
sqlsrv_close($conn);
?>
</html>
答案 0 :(得分:0)
默认表单方法是GET,而不是POST。如果您想使用POST(在这种情况下应该使用),请使用:
<form action=".." method="post" onsubmit="...">
...
</form>
第二个问题是$ query字符串。它应该使用这样的参数:
$query = "DELETE ... WHERE License_Group_ID = ?; " ;
PS:使用PDO比使用sqlsrv_ *函数更好。