我正在尝试根据表单的输入对数据库执行更新但面临问题。我已经尝试过以下但它没有在数据库上执行命令。它需要读取一个值作为决策,并根据决定进行查询。任何人都可以在这里发现问题吗?
html表单代码:
<center><div class="container">
<form action="update.php" onsubmit="return confirm('Are you sure you wish to update ?');">
<div class="row">
<div class="col-25">
<label for="decision">Would you like to add or subtract from current quantity?</label>
</div>
<div class="col-75">
<select id="decision" name="decision">
<option value="add">Add</option>
<option value="subtract">Subtract</option>
</select>
</div>
</div>
<br>
<div class="row">
<div class="col-25">
<label for="License Group ID">License Group ID</label>
</div>
<div class="col-75">
<input type="number" name="LicenseGroupID" placeholder="LicenseGroupID">
</div>
</div>
<br>
<div class="row">
<div class="col-25">
<label for="Quantity">Quantity</label>
</div>
<div class="col-75">
<input type="number" name="Quantity" placeholder="Quantity">
</div>
</div>
<br>
<div class="row">
<input type="submit" value="Update">
</div>
update.php
<html>
<?php
$serverName = "tcp:xxx,1433";
$options = array( "UID" => "aalicensemanager", "PWD" => "xxx", "Database" => "AALicenseManager");
$conn = sqlsrv_connect($serverName, $options);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
$decision = $_POST['decision'];
$LicenseGroupID = $_POST['LicenseGroupID'];
$Quantity = $_POST['Quantity'];
$query = " CASE WHEN $decision = 'add'
THEN
UPDATE dbo.[tbl_license_group]
SET Quantity = Quantity + '$Quantity'
WHERE License_Group_ID = '$LicenseGroupID'
ELSE WHEN $decision = 'subtract'
THEN
UPDATE dbo.[tbl_license_group]
SET Quantity = Quantity - '$Quantity'
WHERE License_Group_ID = '$LicenseGroupID'" ;
$params1 = array($decision,$LicenseGroupID,$Quantity);
$result = sqlsrv_query($conn,$query,$params1);
sqlsrv_close($conn);
?>
</html>
答案 0 :(得分:0)
您的更新语句应该类似......
d = {'col1': [LINESTRING], 'col2': [(174.76028, -36.80417),(174.76041 -36.80389), (175.76232 -36.82345)]
df = pd.DataFrame(d)
您需要将case语句放在case语句中的update语句而不是update语句中。