0

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

Edited by Awah Mohamed: nothing

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by chrishea
0

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';
0

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
)";

0

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.

This topic has been dead for over six months. 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.