如何查看MySQL查询错误详细信息?

时间:2011-09-04 18:25:25

标签: php mysql sql error-handling

我正在尝试插入表格,但它不起作用。所以我告诉我的应用程序,如果你不能INSERT然后重定向到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
  }
}

2 个答案:

答案 0 :(得分:8)

echo mysql_error();

答案 1 :(得分:2)

echo mysql_errno();  
echo mysql_error();

php.net manual