1. I want to insert something into database. They all with time and date, the time type is like 'day month year time' 26 October 2010, 08:16 29 October 2010, 13:45 31 October 2010, 1:02 pm 30 October 2010, 11:54 am Some time and date are 24-hour, some are 12-hour. How to use PHP code transform them to a database time type? for that I can run PHP mysql query be sorted by time? 2. I do not want to insert duplicate data, I use below code, but failed. How to solve? Thanks. mysql_query("INSERT INTO table (name,title,date) VALUES ('".$name."','".$title."','".$date."')" where title not in (select title from table) and name not in (select name from table)); HTML:
Hi look at the date() and time() functions to format your date. and strtotime() function to get a timestamp to be used by the above to functions
Date is a keyword for mysql and so it's probably throwing an error because of that. Change date to `date` with ticks to avoiod this problem. mysql_query("INSERT INTO table (name,title,`date`) VALUES ('".$name."','".$title."','".$date."')" where title not in (select title from table) and name not in (select name from table)); Code (markup):
Thanks KingOle, I tried `date`, but it also failed. when i use mysql_query("INSERT INTO table (name,title,`date`) VALUES ('".$name."','".$title."','".$date."')"); Code (markup): it worked. use mysql_query("INSERT INTO table (name,title,`date`) VALUES ('".$name."','".$title."','".$date."') where title not in (select title from table) and name not in (select name from table)" ); Code (markup): it failed, it can not insert anyone, if I empty my database. And... do you know the first question? How to transform my time to a database time type?
Sounds like you have not reinstated the fields after dropping your database thats why you cant add the fields. As for time add a column called itime then use this code $itime=time(); Then use SQL sort by to order you database.
Yes, $db = mysql_connect("localhost","root","root") or dir("can not connect Mysql Server"); mysql_select_db("table",$db) or dir("can not connect Mysql Server"); I think I write a wrong code...