删除php无法正常工作

时间:2017-06-08 06:45:13

标签: php

我的数据库没有唯一ID。

include('php_connect.php');

// check if the 'Userid' variable is set in URL, and check that it is valid
if (isset($_GET['ServerName']))
{
// get id value
    $userid = $_GET['ServerName'];     
// delete the entry
    $strSQL = "DELETE from server WHERE ServerName = (?)";
    $params = array($userid);
    $stmt = sqlsrv_query( $conn, $strSQL, $params);
    if( $stmt ){
        sqlsrv_commit( $conn );
        echo "Record Deleted";
        }
    else
    {
        echo $params[0];
        echo "statement error.<br />";
        die( print_r( sqlsrv_errors(), true));
    }
    sqlsrv_close( $conn );    
}
else
// if id isn't set, or isn't valid, redirect back to view page
{
    echo "WTH Something happened to the ServerName!.<br />";
    echo "Better start over.<br />";
}

?>

结果如下:

WTH Something happened to the ServerName!
Better start over

3 个答案:

答案 0 :(得分:0)

$_GET['ServerName']更改为$_GET['Userid']

if (isset($_GET['Userid']))
{
    //rest of codes

答案 1 :(得分:0)

根据您对代码的评论,您应该检查servername的用户名:

检查&#39;用户ID&#39;变量在URL中设置,并检查它是否有效

if (isset($_GET['ServerName']))
{

if (isset($_GET['Userid']))
{

答案 2 :(得分:0)

简单

 if(!$_GET['ServerName']){}