使用php中的单选按钮从MS SQL SERVER中删除行
Deleting Rows from MS SQL SERVER using radio button in php
我想使用php删除MS SQL中的行,但
$ids = $_POST['id'];
有问题当我点击单选按钮和"删除"按钮时,就会发生这种情况
<?php
$serverName = "kwekwe-PC'SQLEXPRESS";
$connectionInfo = array( "Database"=>"customerdb", "UID"=>"dbadmin", "PWD"=>"kwekwe" );
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
//declare the SQL statement that will query the database
$query = "SELECT * FROM Customer_Details";
//execute the SQL query and return records
$result = sqlsrv_query($conn, $query)
or die( print_r( sqlsrv_errors(), true));
//Show results in table
$o = '<table border=1 id="myTable">
<thead>
<tr>
<th> </th>
<th>REC NUMBER</th>
<th>CUSTOMER ID</th>
<th>CUSTOMER NAME</th>
<th>SEC-REGISTERED NAME</th>
<th>TIN NUMBER</th>
<th>STORE TYPE</th>
<th>SIZE OF BUSINESS</th>
<th>SELLER ID</th>
<th>DATE OF ESTABLISHMENT</th>
<th>TELEPHONE#/FAX</th>
<th>PAYMENT TERMS</th>
<th>SHIPPING INSTRUCTIONS</th>
<th>NUMBER OF DOORS</th>
<th>NUMBER OF WAREHOUSES</th>
<th>OWNER</th>
<th>PURCHASER/S</th>
<th>ACCOUNTING HEAD</th>
<th>WAREHOUSE HEAD</th>
<th>OTHER PERSONNEL</th>
<th>PAYMENT TERMS 2</th>
<th>COLLECTION SCHEDULE</th>
<th>DISCOUNT</th>
<th>VOLUME</th>
<th>MERCHANDISING</th>
<th>VEHICLE</th>
<th>DISTRIBUTION</th>
<th>CSL</th>
<th>ASSORTMENT</th>
<th>PRICING</th>
<th>MARGIN</th>
<th>PRICE</th>
<th>PROMOTION</th>
<th>PEOPLE</th>
<th>OTHERS</th>
<th>REPLENISHMENT ORDERS</th>
<th>ASSORTMENT/MERCHANDISING</th>
<th>NEW PRODUCTS</th>
<th>PRICING/PROMOTION</th>
<th>PICTURE</th>
</tr>
</thead><tbody>';
while ( $record = sqlsrv_fetch_array($result) )
{
$o .= '<tr><td><input type=radio name=id value='.$record ['Rec_No'].'></td>';
$o .= '<td>'.$record ['Rec_No'].'</td>';
$o .= '<td>'.$record ['Cust_ID'].'</td>';
$o .='<td>'.$record ['Cust_Name'].'</td>';
$o .='<td>'.$record ['SEC_Name'].'</td>';
$o .='<td>'.$record ['TIN Number'].'</td>';
$o .='<td>'.$record ['Store_Type'].'</td>';
$o .='<td>'.$record ['Size of Business'].'</td>';
$o .='<td>'.$record ['Seller_ID'].'</td>';
$o .='<td>'.date('F d, Y',strtotime($record ['Date of Establishment'])).'</td>';
$o .='<td>'.$record ['Telephone/Fax'].'</td>';
$o .='<td>'.$record ['Payment Terms'].'</td>';
$o .='<td>'.$record ['Shipping Instructions'].'</td>';
$o .='<td>'.$record ['Number of Doors'].'</td>';
$o .='<td>'.$record ['Number of Warehouses'].'</td>';
$o .='<td>'.$record ['Owner'].'</td>';
$o .='<td>'.$record ['Purchaser(s)'].'</td>';
$o .='<td>'.$record ['Accounting Head'].'</td>';
$o .='<td>'.$record ['Warehouse Head'].'</td>';
$o .='<td>'.$record ['Other Personnel'].'</td>';
$o .='<td>'.$record ['Payment Terms 2'].'</td>';
$o .='<td>'.$record ['Collection Schedule'].'</td>';
$o .='<td>'.$record ['Discount'].'</td>';
$o .='<td>'.$record ['Volume'].'</td>';
$o .='<td>'.$record ['Merchandising'].'</td>';
$o .='<td>'.$record ['Marketing Vehicle'].'</td>';
$o .='<td>'.$record ['Distribution'].'</td>';
$o .='<td>'.$record ['CSL'].'</td>';
$o .='<td>'.$record ['Assortment'].'</td>';
$o .='<td>'.$record ['Pricing'].'</td>';
$o .='<td>'.$record ['Margin'].'</td>';
$o .='<td>'.$record ['Price'].'</td>';
$o .='<td>'.$record ['Promotion'].'</td>';
$o .='<td>'.$record ['People'].'</td>';
$o .='<td>'.$record ['Others'].'</td>';
$o .='<td>'.$record ['Replenishment Orders'].'</td>';
$o .='<td>'.$record ['Assortment/Merchandising'].'</td>';
$o .='<td>'.$record ['New Products'].'</td>';
$o .='<td>'.$record ['Pricing/Promotions'].'</td>';
$o .='<td><img height=127 width=127 src="data:image/png;base64,' . $record['image'] . '"></td>';
$o .='</tr>';
}
$o .= '</tbody></table>';
echo $o;
//free result set memory
//mssql_free_result($result);
//close the connection
//sqlsrv_close($dbhandle);
?>
<form action="delete.php" method="POST">
<br><input type="submit" value="Delete" name="submit">
</form>
<?php
$ids = $_POST['id'];
if (isset($_POST['submit']))
{
$serverName = "MELODY-PC'SQLEXPRESS";
$connectionInfo = array( "Database"=>"customerdb", "UID"=>"dbadmin", "PWD"=>"melodyjerah" );
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$sql = "DELETE FROM Customer_Details WHERE Rec_Num =".$ids;
sqlsrv_query($conn, $sql);
echo "Row with ID ".$ids." has been deleted!";
}
?>
您想一次删除多行还是单行?如果要删除多行,请使用复选框而不是单选按钮否则使用超链接删除单行
像这个
$o .= '<tr><td><a href="delete.php?id='.$record["Rec_No"].'">Delete</a></td>';
删除多行
$o .= '<tr><td><input type="checkbox" name="id[]" value='.$record ['Rec_No'].'></td>';
试试这个:
$serverName = "kwekwe-PC'SQLEXPRESS";
$connectionInfo = array("Database" => "customerdb", "UID" => "dbadmin", "PWD" => "kwekwe");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
//declare the SQL statement that will query the database
$query = "SELECT * FROM Customer_Details";
//execute the SQL query and return records
$result = sqlsrv_query($conn, $query)
or die(print_r(sqlsrv_errors(), true));
//Show results in table
$o = '<table border=1 id="myTable">
<thead>
<tr>
<th> </th>
<th>REC NUMBER</th>
<th>CUSTOMER ID</th>
<th>CUSTOMER NAME</th>
<th>SEC-REGISTERED NAME</th>
<th>TIN NUMBER</th>
<th>STORE TYPE</th>
<th>SIZE OF BUSINESS</th>
<th>SELLER ID</th>
<th>DATE OF ESTABLISHMENT</th>
<th>TELEPHONE#/FAX</th>
<th>PAYMENT TERMS</th>
<th>SHIPPING INSTRUCTIONS</th>
<th>NUMBER OF DOORS</th>
<th>NUMBER OF WAREHOUSES</th>
<th>OWNER</th>
<th>PURCHASER/S</th>
<th>ACCOUNTING HEAD</th>
<th>WAREHOUSE HEAD</th>
<th>OTHER PERSONNEL</th>
<th>PAYMENT TERMS 2</th>
<th>COLLECTION SCHEDULE</th>
<th>DISCOUNT</th>
<th>VOLUME</th>
<th>MERCHANDISING</th>
<th>VEHICLE</th>
<th>DISTRIBUTION</th>
<th>CSL</th>
<th>ASSORTMENT</th>
<th>PRICING</th>
<th>MARGIN</th>
<th>PRICE</th>
<th>PROMOTION</th>
<th>PEOPLE</th>
<th>OTHERS</th>
<th>REPLENISHMENT ORDERS</th>
<th>ASSORTMENT/MERCHANDISING</th>
<th>NEW PRODUCTS</th>
<th>PRICING/PROMOTION</th>
<th>PICTURE</th>
</tr>
</thead><tbody>';
while ($record = sqlsrv_fetch_array($result)) {
$o .= '<tr><td><input type=radio name=id value=' . $record ['Rec_No'] . '></td>';
$o .= '<td>' . $record ['Rec_No'] . '</td>';
$o .= '<td>' . $record ['Cust_ID'] . '</td>';
$o .='<td>' . $record ['Cust_Name'] . '</td>';
$o .='<td>' . $record ['SEC_Name'] . '</td>';
$o .='<td>' . $record ['TIN Number'] . '</td>';
$o .='<td>' . $record ['Store_Type'] . '</td>';
$o .='<td>' . $record ['Size of Business'] . '</td>';
$o .='<td>' . $record ['Seller_ID'] . '</td>';
$o .='<td>' . date('F d, Y', strtotime($record ['Date of Establishment'])) . '</td>';
$o .='<td>' . $record ['Telephone/Fax'] . '</td>';
$o .='<td>' . $record ['Payment Terms'] . '</td>';
$o .='<td>' . $record ['Shipping Instructions'] . '</td>';
$o .='<td>' . $record ['Number of Doors'] . '</td>';
$o .='<td>' . $record ['Number of Warehouses'] . '</td>';
$o .='<td>' . $record ['Owner'] . '</td>';
$o .='<td>' . $record ['Purchaser(s)'] . '</td>';
$o .='<td>' . $record ['Accounting Head'] . '</td>';
$o .='<td>' . $record ['Warehouse Head'] . '</td>';
$o .='<td>' . $record ['Other Personnel'] . '</td>';
$o .='<td>' . $record ['Payment Terms 2'] . '</td>';
$o .='<td>' . $record ['Collection Schedule'] . '</td>';
$o .='<td>' . $record ['Discount'] . '</td>';
$o .='<td>' . $record ['Volume'] . '</td>';
$o .='<td>' . $record ['Merchandising'] . '</td>';
$o .='<td>' . $record ['Marketing Vehicle'] . '</td>';
$o .='<td>' . $record ['Distribution'] . '</td>';
$o .='<td>' . $record ['CSL'] . '</td>';
$o .='<td>' . $record ['Assortment'] . '</td>';
$o .='<td>' . $record ['Pricing'] . '</td>';
$o .='<td>' . $record ['Margin'] . '</td>';
$o .='<td>' . $record ['Price'] . '</td>';
$o .='<td>' . $record ['Promotion'] . '</td>';
$o .='<td>' . $record ['People'] . '</td>';
$o .='<td>' . $record ['Others'] . '</td>';
$o .='<td>' . $record ['Replenishment Orders'] . '</td>';
$o .='<td>' . $record ['Assortment/Merchandising'] . '</td>';
$o .='<td>' . $record ['New Products'] . '</td>';
$o .='<td>' . $record ['Pricing/Promotions'] . '</td>';
$o .='<td><img height=127 width=127 src="data:image/png;base64,' . $record['image'] . '"></td>';
$o .='</tr>';
}
$o .= '</tbody></table>';
?>
<form action="delete.php" method="POST">
<?php echo $o; ?>
<br><input type="submit" value="Delete" name="submit">
</form>
<?php
if (isset($_POST['submit'])) {
$serverName = "MELODY-PC'SQLEXPRESS";
$connectionInfo = array("Database" => "customerdb", "UID" => "dbadmin", "PWD" => "melodyjerah");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
if(isset($_POST['id']) && !empty($_POST['id'])){
$sql = "DELETE FROM Customer_Details WHERE Rec_No =" . $_POST['id'];
sqlsrv_query($conn, $sql);
echo "Row with ID " . $_POST['id'] . " has been deleted!";
}else{
echo "ID is empty";
}
}
相关文章:
- 如何使用angular js从2个表(在sql server中)中提取数据
- 使用谷歌地图、C#、ASP.net、SQL Server显示带有标记的地图.地图未显示
- 使用Javascript或SQL Server将Outlook电子邮件发送到SQL表
- 如何使用 ajax 从 sql Server 获取单选按钮的值,并表示列表单选按钮
- 如何在不刷新页面的情况下从 PHP 中的 SQL Server 数据库获取数据
- 使用php中的单选按钮从MS SQL SERVER中删除行
- 将数据从本地SQL Server同步到Internet上的MySQL Server(实时服务器)
- 如何修复MS SQL Server 2008R2/2012和Javascript之间的日期差异
- 正在尝试在NodeJS上连接到SQL Server 2014
- 从sql server中用javascript创建HTML表
- 在Sql Server上使用pivottable.js和PHP查询
- SQL Server日期(不是日期时间)到JavaScript日期-休息一天
- 当返回的查询不为空时,来自 php 的 MS SQL Server 过程失败并显示 500
- 上载图像、显示,然后写入 SQL Server
- JS和SQL Server之间的UTC时间戳不同
- 如何更新在 SQL Server 数据库中发生某些更改时通过 jsp 显示的表内容
- SQL Server 代理作业:从网站调用
- PHP & SQL Server Error Handling?
- SQL Server 实时推送通知到 Node.JS
- 在 JavaScript 中替换 SQL Server 中的回车符和换行符