如何解决php / mysql插入失败问题?

I can't get this mysql query to work properly. It completes with no errors but no information is inserted into the database. I'm not so concerned about finding an imediate solution but how can I get mysql to report what's going on behind the scenes?

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$tempProf = $_POST["professor"];
$tempProfArray = explode("=",$tempProf);
$prof = $tempProfArray[1];

$tempName = $_POST["name"];
$tempNameArray = explode("=",$tempName);
$name = $tempNameArray[1];

$tempNum = $_POST["number"];
$tempNumArray = explode("=",$tempNum);
$num = $tempNumArray[1];

$tempSec = $_POST["section"];
$tempSecArray = explode("=",$tempSec);
$section = $tempSecArray[1];

$tempCat = $_POST["category"];
$tempCatArray = explode("=",$tempCat);
$category = $tempCatArray[1];

$con=mysqli_connect("localhost","root","*****","******");

$result = mysqli_query($con,"SELECT * FROM professors where id='$prof'");
$row = mysqli_fetch_array($result);



if(empty($prof) || empty($name) || empty($num) || empty($section) || empty($category))
{
    echo "emptyField";
}
elseif(!is_numeric($num)  || !is_numeric($section))
{
    echo "NaN";
}
elseif(empty($row))
{
    mysqli_query($con,"INSERT INTO classes (className, classNumber, section, classCategory)
    VALUES ('$name','$num','$section','$category')");

    $classTemp = mysqli_query($con,"SELECT id FROM classes where className='$name' and classNumber='$num' and section ='$section'");
    $classTempArray = mysqli_fetch_array($classTemp);
    $classId = $classTempArray['id'];

    mysqli_query($con,"INSERT INTO professors (name, classes) VALUES ('$name','$classId')");

    $profTemp = mysqli_query($con,"SELECT id FROM professors where name='$name'");
    $profTempArray = mysqli_fetch_array($profTemp);
    $profId = $classTempArray['id'];

    mysqli_query($con,"INSERT INTO classes (professor) VALUES ('$profId') where id ='$classId'");

}
else
{
    $profName = $row['id'];
    mysqli_query($con,"INSERT INTO classes ($profName, className, classNumber, section, classCategory)
VALUES ('$prof', '$name','$num','$section','$category')");
}

?>

How to trace it? You put in proper error handling. mysqli in procedural mode will return boolean FALSE on failure. None of your code actually checks those return values, and simply assumes everything works.

Your basic query code flow should be

$result = mysqli_query(...);
if (!$result) {
   die(mysqli_error());
}

All of your code is also vulnerable to SQL injection attacks. Do NOT put this code into production, or even a testing environment, until you know how to handle this problem.

Enable MySQL log, and then
tail -f /path/to/the/log/file

You can monitor what queries and when are executed from the MySql server point of view.

Yo can also filter with grep
tail -f /path/to/to/log/file | grep 'INSERT' --color

you should use pdo (http://php.net/manual/en/book.pdo.php) as it is safer than mysqli.

you can debug errors in msqli with http://php.net/manual/en/mysqli.error.php