creating tables script *solved*
Posted: Sun Jun 10, 2007 11:59 am
i am trying to create four tables. my script creates the first table "userdata" and the third "prayerlog" but for some reason not the second or fourth. here is my code:
why is this happening?
Code: Select all
<?php
// set your infomation.
$dbhost='localhost';
$dbusername='david';
$dbuserpass='mypassword';
$dbname='test';
// connect to the mysql database server.
$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);
echo "success in database connection.";
// select the specific database name we want to access.
if (!mysql_select_db($dbname)) die(mysql_error());
echo "success in database selection.";
// add a table to the selected database
$result="CREATE TABLE userdata (
userid int(20) NOT NULL auto_increment,
username VARCHAR(25),
password VARCHAR(25),
email VARCHAR(30),
link1 VARCHAR(25),
link2 VARCHAR(25),
link3 VARCHAR(25),
link4 VARCHAR(25),
userimage VARCHAR(200),
PRIMARY KEY (userid),
UNIQUE KEY id (userid)
)";
if (mysql_query($result)){
echo "success in table creation.";
} else {
echo "no table created.";
}
// add a table to the selected database
$result = "CREATE TABLE dailyvibe (
postid int(20) NOT NULL auto_increment,
timestamp varchar(30) NOT NULL,
userlink varchar(30) NOT NULL,
entry longtext NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY id (id)
)";
if (mysql_query($result)){
echo "success in table creation.";
} else {
echo "no table created.";
}
// add a table to the selected database
$result = "CREATE TABLE prayerlog (
postid int(20) NOT NULL auto_increment,
timestamp varchar(30) NOT NULL,
userlink varchar(30) NOT NULL,
entry longtext NOT NULL,
reply bool,
replytext longtext NOT NULL,
PRIMARY KEY (postid),
UNIQUE KEY id (postid)
)";
if (mysql_query($result)){
echo "success in table creation.";
} else {
echo "no table created.";
}
// add a table to the selected database
$result = "CREATE TABLE publicvibe (
postid int(20) NOT NULL auto_increment,
timestamp varchar(30) NOT NULL,
userlink varchar(30) NOT NULL,
entry longtext NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY id (id)
)";
if (mysql_query($result)){
echo "success in table creation.";
} else {
echo "no table created.";
}
?>