SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Aug 25, 2004, 08:28 #1
- Join Date
- Aug 2004
- Location
- Kingston
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Creating a table with mysql and php.
Hello me again,
I am trying to create a table in php connecting to a mysql DB. I have tried a number of different formats and they have not worked. I have searched the internet for more examples and nothing is working. Could someone maybe take a look at it and tell me what I am doing wrong. I will give you my most recent code attempt.
<?php
$connection=mysql_connect("localhost", "root", "") or die("Could not connect!");
mysql_select_db("tutorial_db", $connection) or die("Could not select a valid DB");
$sql = CREATE TABLE person ( id INT NOT NULL AUTO_INCREMENT ,
name VARCHAR( 35 ) DEFAULT 'Noname' NOT NULL ,
surname VARCHAR( 35 ) DEFAULT 'Nosurname' NOT NULL ,
sex VARCHAR( 1 ) NOT NULL ,
age SMALLINT UNSIGNED NOT NULL ,
PRIMARY KEY ( id ) );
mysql_query($sql);
mysql_close();
?>
Thanks,
Wayzer
-
Aug 25, 2004, 08:32 #2
- Join Date
- Jun 2004
- Location
- Mumbai
- Posts
- 447
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:<?php
$connection=mysql_connect("localhost", "root", "") or die("Could not connect!");
mysql_select_db("tutorial_db", $connection) or die("Could not select a valid DB");
$sql = "CREATE TABLE person ( id INT NOT NULL AUTO_INCREMENT ,
name VARCHAR( 35 ) DEFAULT 'Noname' NOT NULL ,
surname VARCHAR( 35 ) DEFAULT 'Nosurname' NOT NULL ,
sex VARCHAR( 1 ) NOT NULL ,
age SMALLINT UNSIGNED NOT NULL ,
PRIMARY KEY ( id ) )";
mysql_query($sql);
mysql_close();
?>Anjanesh
-
Aug 25, 2004, 08:33 #3
- Join Date
- Jul 2004
- Location
- Canada
- Posts
- 251
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
www.mysql.com and download MySQLcc or google phpMyAdmin, download, and install that. They're both reasonably good MySQL front-ends, that will make creating/editing tables and such simple.
Otherwise, mysql_query($sql) or print(mysql_error()); will print the MySQL error.Adam A Flynn
php4 SimpleXML-like XML Parser
-
Aug 25, 2004, 08:49 #4
- Join Date
- Aug 2004
- Location
- Kingston
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, It was the double quotes around the create table string. Silly mistake I guess, but that is why we all love programming.
Thanks again guys.
Bookmarks