andyg666 Posted August 31, 2006 Share Posted August 31, 2006 I'm using XAMPP, with PHP 5 and MySQL 5. I have created a database and I am attempting to use the following PHP code to create tables:[code]mysql_select_db("my_db", $con);$sql = "CREATE TABLE tblActivity (ActivityID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(ActivityID),LocationID int,ActivityType varchar(15),Accessibility text,Popularity int(2),AvgPopulation int(7),Keywords text,Description text,CreatedBy varchar(15),CreationDate datetime(yyyy-mm-dd hh:mm:ss),ModifyDate datetime(yyyy-mm-dd hh:mm:ss))";$result = mysql_query($sql,$con);if (!$result) { die("Could not create tblActivity: " . mysql_error() . "<BR>"); } else { echo "Creating tblActivity...<br>"; } [/code] This code returns the following error message:[quote]"Could not create tblActivity: 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 '(yyyy-mm-dd hh:mm:ss), ModifyDate datetime(yyyy-mm-dd hh:mm:ss) )' at line 13"[/quote]I'm not sure what is incorrect--I've checked this against tons of examples and tutorials. I can't find any errors in the syntax. Any ideas?Thanks! Link to comment https://forums.phpfreaks.com/topic/19273-problem-with-create-table/ Share on other sites More sharing options...
fenway Posted August 31, 2006 Share Posted August 31, 2006 Drop those invalid modifiers to the datetime columns. Link to comment https://forums.phpfreaks.com/topic/19273-problem-with-create-table/#findComment-83684 Share on other sites More sharing options...
andyg666 Posted September 1, 2006 Author Share Posted September 1, 2006 i copied them directly from the tutorials at w3schools.com.i've actually tried it without them ( just datetime() ) and i get the same error message. let me try it one more time and i'll report back. thanks. Link to comment https://forums.phpfreaks.com/topic/19273-problem-with-create-table/#findComment-84049 Share on other sites More sharing options...
andyg666 Posted September 1, 2006 Author Share Posted September 1, 2006 changing the last two lines to this:[code]CreationDate datetime NOT NULL default '0000-00-00 00:00:00',ModifyDate timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP)";[/code]did the trick.thanks. Link to comment https://forums.phpfreaks.com/topic/19273-problem-with-create-table/#findComment-84092 Share on other sites More sharing options...
fenway Posted September 1, 2006 Share Posted September 1, 2006 Glad you got it working.. it would have worked without the parentheses as well. Link to comment https://forums.phpfreaks.com/topic/19273-problem-with-create-table/#findComment-84120 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.