0

I've just started working with PHP and MySQL, and I'm trying to create a table in MySQL. If I've got this right, I'm trying to do so by going to my host's SQL MyAdmin page and typing in

mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
 name VARCHAR(30), 
 age INT)")

in the query tab. I get an error saying that my syntax is wrong. Any advice?

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by |-|x
1

I believe the PRIMARY statement needs to go at then end of all the column definitions

CREATE TABLE example (
  id int NOT NULL AUTO_INCREMENT,
  name varchar(30),
  age int,
  PRIMARY KEY (id)
)
0

I don't thing primarykey statement creates error,
I don't thing its is error in query, It may be #1046 - No database selected error,if so create database and select that

try with that

create database db_name;
use db_name;
CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
 name VARCHAR(30), 
 age INT)

Edited by anand01

1

I get an error saying that my syntax is wrong

What is the actual error message you are getting? Is it from mysql or from PHP?

the line of code you posted doesn't have a semicolon at the end, which will generate a syntax error in php if its like that in your page.

Edited by |-|x

Votes + Comments
The error message doesn't actually display an error code; very strange.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.