Click to See Complete Forum and Search --> : create squal table problem


kproc
04-17-2006, 04:08 PM
Below is some code that I'm tryingto use to create a sql table, I'm not having any luck. I know that I can connect to the database, as if I copy this the code from this post

it works


http://www.webdeveloper.com/forum/showthread.php?t=102318
any idea what is worng, ( I know the password spot is blank)

<html><head><title>family_info</title></head>
<body>
<?
$db="mydata_tomorrownextweek_com";
$pw = "";
$user = "dbm.tomorrownextweek.com";
$link = mysql_connect("sqlc11.megasqlservers.com", $user, $pw);
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db, $link)
or die("Select DB Error: ".mysql_error());
//create table
mysql_query("CREATE TABLE users (
userid int(25) NOT NULL auto_increment,
first_name varchar(25) NOT NULL default '',
last_name varchar(25) NOT NULL default '',
email_address varchar(25) NOT NULL default '',
username varchar(25) NOT NULL default '',
password varchar(255) NOT NULL default '',
info text NOT NULL,
user_level enum('0','1','2','3') NOT NULL default '0',
signup_date datetime NOT NULL default '0000-00-00 00:00:00',
last_login datetime NOT NULL default '0000-00-00 00:00:00',
activated enum('0','1') NOT NULL default '0',
PRIMARY KEY (userid)
)or die("Create table Error: ".mysql_error());
mysql_close($link);

?>
</body>

</html>

chazzy
04-17-2006, 04:56 PM
can you tell us what error you're getting?

kproc
04-17-2006, 05:05 PM
When I run it, I get no error, just a blank screen

chazzy
04-17-2006, 06:29 PM
you're not closing your create table properly. it's missing a closing )

aaronbdavis
04-17-2006, 06:44 PM
As Chazzy said you are missing a closing parenthesis, and you are also missing a closing double-quote. I posted a corrected version below.

<?
$db="mydata_tomorrownextweek_com";
$pw = "";
$user = "dbm.tomorrownextweek.com";

$link = mysql_connect("sqlc11.megasqlservers.com", $user, $pw);

if (! $link) { die("Couldn't connect to MySQL"); }

mysql_select_db($db, $link) or die("Select DB Error: ".mysql_error());

//create table

mysql_query("CREATE TABLE users (
userid int(25) NOT NULL auto_increment,
first_name varchar(25) NOT NULL default '',
last_name varchar(25) NOT NULL default '',
email_address varchar(25) NOT NULL default '',
username varchar(25) NOT NULL default '',
password varchar(255) NOT NULL default '',
info text NOT NULL,
user_level enum('0','1','2','3') NOT NULL default '0',
signup_date datetime NOT NULL default '0000-00-00 00:00:00',
last_login datetime NOT NULL default '0000-00-00 00:00:00',
activated enum('0','1') NOT NULL default '0',
PRIMARY KEY (userid)
)")or die("Create table Error: ".mysql_error());

mysql_close($link);

?>