简体   繁体   English

如何执行MySql查询?

[英]How to execute a MySql query?

I'm executing a simple delete query in mysql using php. 我正在使用php在mysql中执行简单的删除查询。 I don't know wrong with this query: 我不知道这个查询有错:

  $delid=$_REQUEST['did'];
if(($del=mysql_query("delete from achieva_trainee_mail_tble where id='".$delid."'"))==true)
{
    header("location:viewtrainee.php?dl=1");
}
else
{
    echo("<script>alert('Failure please try again later...');</script>");
}

I can get the 'did' in the page using '$_REQUEST['did']. 我可以使用'$ _REQUEST ['did']在页面中获得'did'。 But it isn't redirecting to the viewtrainee.php page, it goes to the else part. 但是它没有重定向到viewtrainee.php页面,而是转到else部分。 I execute the same structure for other files it works fine. 我对其他文件执行相同的结构,效果很好。 What is wrong with this. 这有什么问题。

Use mysql_affected_rows function. 使用mysql_affected_rows函数。

$delid=$_REQUEST['did'];

mysql_query("delete from achieva_trainee_mail_tble where id='".$delid."'"));

if(mysql_affected_rows())
{
    header("location:viewtrainee.php?dl=1");
}
else
{
    echo("<script>alert('Failure please try again later...');</script>");
}

mysql_query return the result and not the success state... use mysql_error or mysql_errno like this: mysql_query返回结果而不是成功状态...像这样使用mysql_error或mysql_errno:

$didName = 'did';
$delId = null;
$failed = true;

if(array_key_exists($didName, $_REQUEST)) {
    $delId = $_REQUEST[$didName];
    mysql_query("delete from achieva_trainee_mail_tble where id='".mysql_real_escape_string($delId, $yourConnection)."'", $yourConnection);

    if(false == mysql_errno($yourConnection)) {
        $failed = true;
    }
}

if(false == $failed) {
       header("location:viewtrainee.php?dl=1");
}
else {
    echo("<script>alert('Failure please try again later...');</script>");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM