hi , my server usually tells me that there is a syntax error so what is it?
the error is in line 12 but i dont know what is it
here is the code :

<?
$mysql_host = "mysql9.000webhost.com";
$mysql_database = "a2354076_post";
$mysql_user = "username";
$mysql_password = "password";
$tbl_name = "posts";
mysql_connect("$mysql_host","$mysql_user","$mysql_password")or die ("cannot connect to DB");
mysql_select_db("$mysql_database")or die("unable to select your database");
$datetime=date("y-m-d h:i:s");
$title=$_POST['title'];
$post=$_POST['post'];
$sql="INSERT INTO $tbl_name(datetime, title, post)values("$datetime","$title","$post")";
$result=mysql_query($sql);
if($result)
{
echo 'success !!!';
echo "<BR>your post is added successfully";
echo "<BR><a href='vew-posts.php'>View posts</a>";
}
else
{
echo "ERROR, your post is not added , please try again or check your database stetup , Awah Mohamad";
}
mysql_close();
?>
$sql="INSERT INTO $tbl_name(datetime, title, post)values('$datetime','$title','$post')";

Please try this:

$sql="INSERT INTO $tbl_name (`datetime`, `title`, `post`) values ('".$datetime."','".$title."','".$post."')";

just to clarify when you insert any value or query any value in a database. then need to have single quotes around them.
the columns don't need to but some put them in anyway.
for example if your title was cheese. it would be:
$sql = "INSERT INTO table (title) values ('cheese')";

therefore your $values must also be wrapped in single quotes, even though they are already in double quotes.
so both the above responses are correct. however using single quotes like in the second reply is messy as everything is appended.

hope this helps :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.