Jump to content

can't create database table


unplugged_web

Recommended Posts

I'm having a problem creating a table for a website. I've used the following code

<?php$con = mysql_connect("hostname/server IP","username","password");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("databasename", $con);$sql = "CREATE TABLE table name (ID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(ID),email varchar(50),)";mysql_query($sql,$con);if (!mysql_query($sql,$con)) echo mysql_error();mysql_close($con);?>

which I know works because I've used it for another site. It's exactly the same database that I'm using I just want to create another table for this site (both sites are on the same server and hosted by the same company).When I go to my browser to activate the code and create the table I get an error saying:

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 ')' at line 6
but I don't know what to change because as I say this code has worked in the past. Both the site it has worked with and this site are using PHP 4.3.2, but I've been told by the hosting company that this will be upgraded to 5 by Christmas.Thanks for any helpCheersLucy
Link to comment
Share on other sites

email varchar(50),)";You have a comma after the last field, you need to remove that in order for the query to work. The last field shouldn't have a comma after it. The code wouldn't have worked on the other site like that, that's not a valid create table statement.

Link to comment
Share on other sites

email varchar(50),)";You have a comma after the last field, you need to remove that in order for the query to work. The last field shouldn't have a comma after it. The code wouldn't have worked on the other site like that, that's not a valid create table statement.
Thanks for that. I removed a few of the fields from the code, but didn't know I had to remove the comma from the last field as well.Thanks
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...