I am currently learning OOP, but I can't figure out how to insert date into database. I have tried:
$time=date('now');
$time=date("timestamp");
$time=date("Y-m-d H:i:s");
$time=date("m/d/y g:i A");
When I submit I get error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2014-03-11 14:18:07'' at line 1
I can't figure this out. Before I did use:
$result = mysql_query ("INSERT INTO test (title,url,time) VALUES ('$title','$url',now())");
I tried to use now() , but it does not seem to work. :/
Update:
Insert:
public function insert($cat,$title,$article,$author,$image,$time)
{
$sql=mysql_query("INSERT INTO blog_posts(cat, title, article, time, author, image) VALUES('$cat', '$title', '$article', '$author', '$image, '$time'");
if(!$sql)
{
echo mysql_error();
}
}
proccess file:
$cat=$_POST['cat'];
$title=$_POST['title'];
$article= $_POST['article'];
$author=$_POST['author'];
$image=$_POST['image'];
$time= date( 'Y-m-d H:i:s' );
$n=new db();
$n->connect();
$n->insert($cat,$title,$article,$author,$image,$time);