Jump to content

Archived

This topic is now archived and is closed to further replies.

andyg666

Problem with Create Table

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Drop those invalid modifiers to the datetime columns.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Glad you got it working.. it would have worked without the parentheses as well.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.