PHP Create Table not working

I’ve been doing php/mysql tutorials all day and trying to get a grasp on everything.

I keep having problems executing a Create Table script and having it work. I’ve been using Terminal to create databases on localhost and I can create tables that way.

But in every tutorial I can’t seem to create a table or insert data into the database through php. I’ve tested the connection to mysql and it is working.

Here is the code for the current create table:

<?
/* Change next two lines */
$db="tutorialdb";
$link = mysql_connect('localhost', 'root', 'password');
if (! $link)
die(mysql_error());
mysql_select_db($db , $link)
or die(mysql_error());
/* create table */
mysql_query("CREATE TABLE birthdays(
 id INT NOT NULL AUTO_INCREMENT,
 PRIMARY KEY(id),
 name VARCHAR(30),
 birthday VARCHAR(7))")
or die(mysql_error()); 
mysql_close($link);

?>

I created the “tutorialdb” in Terminal and “password” is also the password I’m using.

Thanks for any help as it why it’s not working.

sorry, no

integers don’t have “sizes”

INT(5) merely indicates that 5 positions should be displayed when using ZEROFILL

(you could look it up)

INT is perfectly valid by itself

Awesome, thanks for the help!

Hi,

Just you forget the size parameter value of id INT(5)

mysql_query("CREATE TABLE birthdays(

id INT(5) NOT NULL AUTO_INCREMENT,

PRIMARY KEY(id),

name VARCHAR(30),

birthday VARCHAR(7))");

and still if you have any problem then, you follow that “w3schools.com
here i am sure that you easily get the result of your query.

Does an error message get displayed?
(I just tested your query, it seems to be OK)