...

creating mysql tables

Phip
07-27-2002, 08:34 AM
what is wrong with this?

mysql_query("DROP TABLE IF EXISTS ". $pref[tablePre] ."posts;");
mysql_query("CREAT TABLE posts (
id int(10) NOT NULL auto_increment,
date date NOT NULL default,
name varchar(26) NOT NULL default,
email varchar(100) NOT NULL default,
homepage varchar(100) NOT NULL default,
body text NOT NULL,
PRIMARY KEY (id)
)")

firepages
07-27-2002, 11:40 AM
CREAT

as opposed to CREATE I assume ?

EthanX
07-27-2002, 04:55 PM
Try this:

mysql_query("DROP TABLE IF EXISTS ". $pref[tablePre] ."posts;");
mysql_query("CREATE TABLE posts (
id int(10) NOT NULL auto_increment,
date date NOT NULL default,
name varchar(26) NOT NULL default,
email varchar(100) NOT NULL default,
homepage varchar(100) NOT NULL default,
body text NOT NULL,
PRIMARY KEY (id)
)")

Phip
07-27-2002, 05:43 PM
i really need to stop trying to do this so late (early). thanks

Phip
07-27-2002, 06:08 PM
You have an error in your SQL syntax near ' name varchar(26) NOT NULL default, email varchar(100) NOT NULL default,' at line 5

EthanX
07-27-2002, 06:26 PM
Are typing this in phpMyAdmin?
or using PHP file to create it?

Phip
07-27-2002, 06:29 PM
php file, i get the same thing in phpmyadmin when i take out and use the sql code.

EthanX
07-27-2002, 06:36 PM
Try this:


<?php
linkID = @mysql_connect(localhost, "username", "password") or die(mysql_error());

mysql_select_db("databasename", $linkID) or die(mysql_error());

resultID = mysql_query("CREATE TABLE posts(id int(10) NOT NULL auto_increment, date date NOT NULL default, name varchar(26) NOT NULL default, email varchar(100) NOT NULL default, homepage varchar(100) NOT NULL default, body text NOT NULL, PRIMARY KEY (id))", $linkID) or die(mysql_error());

if ($resultID != FALSE)
{
print "The query was successfully executed.";
}
else
{
print "The Query was not successfully executed.";
}

mysql_close($linkID);

?>

Phip
07-27-2002, 06:43 PM
after i gave the two first variables " $ " it gives me an parse error on 11 which is where it tries to create the table.

<?php

$linkID = @mysql_connect(localhost, "", "") or die(mysql_error());



mysql_select_db("mysql", $linkID) or die(mysql_error());


// error on below line
$resultID = mysql_query("CREATE TABLE posts(id int(10) NOT NULL auto_increment, date date NOT NULL default, name varchar(26) NOT NULL default, email varchar(100) NOT NULL default, homepage varchar(100) NOT NULL default, body text NOT NULL, PRIMARY KEY (id))", $linkID) or die(mysql_error());



if ($resultID != FALSE)

{

print "The query was successfully executed.";

}

else

{

print "The Query was not successfully executed.";

}



mysql_close($linkID);



?>

EthanX
07-27-2002, 06:48 PM
<?php
linkID = @mysql_connect(localhost, "username", "password") or die(mysql_error());

mysql_select_db("databasename", $linkID) or die(mysql_error());

$resultID = mysql_query("CREATE TABLE posts(id int(10) NOT NULL auto_increment, date date NOT NULL default, name varchar(26) NOT NULL default, email varchar(100) NOT NULL default, homepage varchar(100) NOT NULL default, body text NOT NULL, PRIMARY KEY (id))", $linkID) or die(mysql_error());

if ($resultID != FALSE)
{
print "The query was successfully executed.";
}
else
{
print "The Query was not successfully executed.";
}

mysql_close($linkID);

?>

Phip
07-27-2002, 06:50 PM
this works, i found the error

<?php

$linkID = @mysql_connect(localhost, "", "") or die(mysql_error());

mysql_select_db("chronicyouth", $linkID) or die(mysql_error());

$resultID = ("CREATE TABLE posts(
id int(10) NOT NULL auto_increment,
date date NOT NULL default,
name varchar(26) NOT NULL default,
email varchar(100) NOT NULL default,
homepage varchar(100) NOT NULL default,
body text NOT NULL,
PRIMARY KEY (id)
), $linkID") or die(mysql_error());

if ($resultID != FALSE)
{
print "The query was successfully executed.";
}
else
{
print "The Query was not successfully executed.";
}

mysql_close($linkID);



?>

), $linkID") or die(mysql_error());

was

)", $linkID) or die(mysql_error());

double quotes needed to be moved.

now, one more problem. it says that it succeeds. but, i can't find it in the database. :p

EthanX
07-27-2002, 06:53 PM
oh sorry.

EthanX
07-27-2002, 06:57 PM
Forgot to do a bunch of stuff, I'm sorry. Here's the code currected.


<?php
$linkID = @mysql_connect("localhost", "", "") or die(mysql_error());

mysql_select_db("database", $linkID) or die(mysql_error());

$resultID = mysql_query("CREATE TABLE posts(id int(10) NOT NULL auto_increment, date date NOT NULL default, name varchar(26) NOT NULL default, email varchar(100) NOT NULL default, homepage varchar(100) NOT NULL default, body text NOT NULL, PRIMARY KEY (id)), $linkID") or die(mysql_error());

if ($resultID != FALSE)
{
print "The query was successfully executed.";
}
else
{
print "The Query was not successfully executed.";
}

mysql_close($linkID);

?>

Phip
07-27-2002, 07:00 PM
You have an error in your SQL syntax near ' name varchar(26) NOT NULL default, email varchar(100) NOT NULL default, homepag' at line 1

by the way thanks for your help

EthanX
07-27-2002, 07:01 PM
Yeah I know.. this error is comfusing.. everthing seems currect.

Phip
07-27-2002, 07:09 PM
aarrrgh!!

Phip
07-27-2002, 07:12 PM
i have to go to a baseball game. wish i could get out of it but anyway... thanks.

EthanX
07-27-2002, 07:15 PM
I'll keep trying.

EthanX
07-27-2002, 07:19 PM
Okay here's my code now, No error messages, but it fails...

<?php
$linkID = @mysql_connect("localhost", "username", "password") or die(mysql_error());

mysql_select_db("database", $linkID) or die(mysql_error());

$resultID = mysql_query("CREATE TABLE posts(
id int(10) NOT NULL auto_increment,
date DATETIME NOT NULL,
name VARCHAR(26) NOT NULL,
email VARCHAR(100) NOT NULL,
homepage VARCHAR(100) NOT NULL,
body text NOT NULL, PRIMARY KEY (id)), $linkID");

if ($resultID != FALSE)
{
print "The query was successfully executed.";
}
else
{
print "The Query was not successfully executed.";
}

mysql_close($linkID);

?>

Phip
07-28-2002, 01:27 AM
i added a or die(mysql_error()) on the end of creating the table and got:

You have an error in your SQL syntax near ' Resource id #1' at line 13

EthanX
07-28-2002, 02:08 AM
Hmm..... I don't know what that is even...

Phip
07-28-2002, 02:13 AM
doesn't anyone know php and mysql?? :p this is a drag. i was looking a book right now, PHP and MySQL Development. I was also looking at other people scripts but they never seem to make sense.

EthanX
07-28-2002, 02:17 AM
I'm sorry.. I've done some of this stuff, but I've never had a error like this. sorry.

Phip
07-28-2002, 02:19 AM
<?php

$linkID = @mysql_connect("localhost", "", "") or die(mysql_error());



mysql_select_db("chronicyouth", $linkID) or die(mysql_error());

mysql_query("
create table test
(
id int unsigned not null auto_increment primary key
)

")or die(mysql_error());

mysql_close($linkID);



?>


this works



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum