【问题标题】:How to see MySQL query error details?如何查看 MySQL 查询错误详情?
【发布时间】:2011-11-10 04:53:59
【问题描述】:

我正在尝试插入表格,但它不起作用。所以我告诉我的应用程序,如果你不能插入然后重定向到 home.php,它正在这样做。所以,某处肯定有错误。但是,它没有告诉我,有没有办法查看查询错误?代码如下:

if(0 === count($errors)){
// Sanitize name and phone number
  $contact_name = mysql_real_escape_string($_POST['name']);
  $phone_number  = mysql_real_escape_string($_POST['phone_number']);

  $query = "INSERT INTO `ani` (`ContactName`,  `PhoneNumber`)
            VALUES            ('$contact_name', '$phone_number'";

  $result = mysql_query($query);

  if(mysql_errno() === 0){
    header("Location: pinless.php");
  } else {
    header("Location: home.php");
    // Here I want to see what the heck is wrong with the above query
    // instead of redirecting
  }
}

【问题讨论】:

  • 您应该接受答案,而不是在标题中添加“已解决”
  • @Uncle Tom,点击你喜欢的答案上的复选标记。它不会花费您任何费用。

标签: php mysql sql error-handling


【解决方案1】:
echo mysql_error();

【讨论】:

  • 是的。 Don't panic 是你应该做的。
【解决方案2】:
echo mysql_errno();  
echo mysql_error();

php.net manual

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多