...

View Full Version : what is wrong with this code?



googleit
08-31-2006, 08:59 PM
i get an error saying
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' email VARCHAR' at line 5
when i run this code



mysql_connect("host", "username", "passwd") or die(mysql_error());
mysql_select_db("dbname) or die(mysql_error());

mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
comments VARCHAR,
email VARCHAR")
or die(mysql_error());

echo "Table Created!";


why do i get this error?

managedinternet
08-31-2006, 09:12 PM
the email & comment VARCHAR should have a value ie 25 ( for 25 character

PRIMARY KEY(id),
name VARCHAR(30),
comments VARCHAR(22),
email VARCHAR(22") limit )


replace 22 with teh amount of characters ( letters ) you want in that value

managedinternet
08-31-2006, 09:12 PM
because email isnt set to UNIQUE you could even replace VARCHAR with TEXT ( no value required )

so use either

mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
comments VARCHAR(22),
email VARCHAR(22)")
or die(mysql_error());

or

mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
comments TEXT,
email TEXT")
or die(mysql_error());

GJay
08-31-2006, 09:21 PM
you're missing a closing " on the select_db line (though possibly a typo while deleting the real dbname...)
and also a closing bracket inside the create table query.

googleit
08-31-2006, 09:23 PM
got this error this time

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6

googleit
08-31-2006, 09:27 PM
Gjay i got this error

Parse error: parse error, unexpected T_STRING in /home/content/b/r/a/bradley/html/create.php on line 7

managedinternet
08-31-2006, 09:28 PM
mysql_select_db("dbname) or die(mysql_error());

Change to

mysql_select_db("dbname") or die(mysql_error());

managedinternet
08-31-2006, 09:30 PM
change EVERYTHING to


mysql_connect("host", "username", "passwd") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());

mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
comments text,
email text")
or die(mysql_error());

echo "Table Created!";

googleit
08-31-2006, 09:30 PM
yeah i have still get the error tho

managedinternet
08-31-2006, 09:37 PM
is that code at the top of the php page ?

trying to determine what line 6 is

i think its the INT.. try this

mysql_connect("host", "username", "passwd") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());

mysql_query("CREATE TABLE example(
id INT(10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
comments text,
email text")
or die(mysql_error());

echo "Table Created!";


that gives your id the possibility of 10 digits

GJay
08-31-2006, 09:39 PM
the closing bracket is still missing...

managedinternet
08-31-2006, 09:41 PM
ahh yes after the email TEXT")
need


email TEXT"))

googleit
08-31-2006, 09:42 PM
finally! gjay & managedinternet thanks for your time.
it was the closing bracket :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum