PHP / SQL脚本有时只能工作

So I have a PHP form that seems to only want to work sometimes. I really don't understand what is wrong with it or why. I will submit test data successfully, but 5 minutes later I will do another test and I get the error message.

I'm not an PHP or SQL expert so help me out!

<?php

$host="localhost"; // Host name
$username="user"; // Mysql username
$password="pass"; // Mysql password
$db_name="database"; // Database name
$tbl_name="table"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form
$title=$_POST['title'];
$body=$_POST['body'];
$date=$_POST['date'];
$tags=$_POST['tags'];

// Insert data into mysql
$sql="INSERT INTO $tbl_name(title, body, date, tags)VALUES('$title', '$body', '$date', '$tags')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}

else {
echo "ERROR";
}
?>

<?php
// close connection
mysql_close();
?>

Thank you! Louie

For first enable error reporting:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

And check what's going on in your code.

Maybe problem is not in PHP but in MySQL Server.