我无法让这个 mysql 查询正常工作。它没有错误地完成,但没有信息被插入到数据库中。我不太关心找到即时解决方案,但我怎样才能让 mysql 报告幕后发生的事情?
<?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')");
}
?>