Web Hosting Talk







View Full Version : MySQL problems


Scott25
03-05-2005, 08:06 AM
im working on the mysql database to store user information so i put in the following code

<?php
require ("connect.php");
$users = " CREATE TABLE `users` (
`username` TEXT( 15 ) NOT NULL ,
`uniqueid` INT( 20 ) NOT NULL ,
`alliance` SET NOT NULL ,
`race` SET NOT NULL ,
`credits` INT( 20 ) DEFAULT '0' NOT NULL ,
`given` INT( 20 ) DEFAULT '0' NOT NULL ,
`recieved` INT( 20 ) DEFAULT '0' NOT NULL ,
`email` TEXT( 20 ) NOT NULL ,
`password` TEXT( 10 ) NOT NULL
)";
$results1 = mysql_query($users) or die (mysql_error());
echo "Successfully created!";
?>

so i then run it to set it up but then it gives me this error

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 '( 15 ) NOT NULL , `uniqueid` INT( 20 ) NOT NULL , `alliance`

any ideas?

zupanm
03-05-2005, 08:59 AM
text does not take a limit.. use varchar for username if you want to limit how many characters it can use

Scott25
03-05-2005, 09:03 AM
<?php
require ("connect.php");
$users = " CREATE TABLE `users` (
`username` VARCHAR( 15 ) NOT NULL ,
`uniqueid` INT( 20 ) NOT NULL ,
`alliance` SET NOT NULL ,
`race` SET NOT NULL ,
`credits` INT( 20 ) DEFAULT '0' NOT NULL ,
`given` INT( 20 ) DEFAULT '0' NOT NULL ,
`recieved` INT( 20 ) DEFAULT '0' NOT NULL ,
`email` VARCHAR( 20 ) NOT NULL ,
`password` VARCHAR( 10 ) NOT NULL
)";
$results1 = mysql_query($users) or die (mysql_error());
echo "Successfully created!";
?>

i changed it to this and still got this

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 'NOT NULL , `race` SET NOT NULL , `credits` INT( 20 )

RRWH
03-05-2005, 09:51 AM
How about taking a quick look at the mySQL manual -specifically dev.mysql.com/doc/mysql/en/numeric-types.html

You will find that an int can be a max value of 10 and a bigint can have a max value of 20

the actual number is the number of digits

wimg
03-07-2005, 05:09 PM
You will need to put something in the 'set'

Vult-r
03-08-2005, 07:08 AM
yep.. you forgot the arguments , should be
`race` SET('human','dwarf','goblin','elf') NOT NULL