我只想插入数据库,但是以下代码既不显示任何错误,也不显示我在数据库中插入的数据。谁能帮助我调试此代码。

<?php
$tips = $_POST["tips"];
$day = $_POST["day"];
$month = $_POST["month"];
$year = $_POST["year"];
$date = $year."-".$month."-".$day;

//echo "$date: $tips";

//========================
//  DataBase Connectivity
//========================
$con=mysqli_connect("localhost","root","","mydb");

// Check connection
if (mysqli_connect_errno($con))
  {
    echo "Failed to connect to Database";
    exit;
  }

else{
// Perform INSERT query
    mysqli_query($con,"INSERT INTO daily_tips (PublishingDate,Tips) VALUES ('$date','$tips')");
    echo "data inserted"
    exit;
}
mysqli_close($con);
?>

最佳答案

尝试

if( mysqli_query($con,"INSERT INTO daily_tips (PublishingDate,Tips) VALUES ('$date','$tips')"))
{
    echo 'success';
}else{
    echo 'failed';
}

10-08 08:00