hey people
seriously , this code is going to kill me
i wrote it yesterday and upto now it cant work
i wrote it more than one time and i review it more than 10 times but i didnt found the error
so this is my code and bellow is the error

<?php
include '../../includes.php/connect.php';
$sql = "CREATE TABLE news(
id INT(8) NOT NULL AUTO_INCREMENT,
title VARCHAR(250) NOT NULL,
news TEXT NOT NULL
)";
$query = mysql_query($sql);
if(!$query)

{
echo "cant create the news table ".mysql_error();
}
else
{
echo "done";
}
?>

cant create the news table Incorrect table definition; there can be only one auto column and it must be defined as a key

Using phpMyAdmin it generates this:

CREATE TABLE `news` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 250 ) NOT NULL ,
`news` TEXT NOT NULL
) ENGINE = InnoDB COMMENT = 'For DaniWeb user The Prince Awah';

In line no 4
$sql = "CREATE TABLE news(
id INT(8) NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(250) NOT NULL,
news TEXT NOT NULL
)";

thank you so much for your help

Prince,

Your statement needs to include:
PRIMARY KEY ( `id` )
)

As the error says, the auto column must be defined as a key. Suggest that you use PHPMyAdmin and so a sample create first (building the structure not by entering an SQL statement). It will tell you the SQL statement that you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.