Helpful Information
 
 
Category: MySQL
creating mysql tables

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)
)")

CREAT

as opposed to CREATE I assume ?

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)
)")

i really need to stop trying to do this so late (early). thanks

You have an error in your SQL syntax near ' name varchar(26) NOT NULL default, email varchar(100) NOT NULL default,' at line 5

Are typing this in phpMyAdmin?
or using PHP file to create it?

php file, i get the same thing in phpmyadmin when i take out and use the sql code.

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);

?>

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);



?>

<?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);

?>

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

oh sorry.

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);

?>

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

Yeah I know.. this error is comfusing.. everthing seems currect.

aarrrgh!!

i have to go to a baseball game. wish i could get out of it but anyway... thanks.

I'll keep trying.

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);

?>

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

Hmm..... I don't know what that is even...

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.

I'm sorry.. I've done some of this stuff, but I've never had a error like this. sorry.

<?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










privacy (GDPR)