paulman888888 Posted June 1, 2008 Share Posted June 1, 2008 What have i done wrong? <?php mysql_connect("something.com", "something", "something") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("something") or die(mysql_error()); echo "Connected to Database"; // Create a MySQL table in the selected database mysql_query("CREATE TABLE example( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), score INT), ipaddress VARCHAR(30), country VARCHAR(30), date VARCHAR (30)") or die(mysql_error()); echo "Table Created!"; ?> Please help Thankyou Quote Link to comment Share on other sites More sharing options...
trq Posted June 1, 2008 Share Posted June 1, 2008 What is the problem? Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted June 1, 2008 Author Share Posted June 1, 2008 it comes up with 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 ' ipaddress VARCHAR(30), country VARCHAR(30), date VARCHAR please help Quote Link to comment Share on other sites More sharing options...
T Horton Posted June 1, 2008 Share Posted June 1, 2008 You forgot "score (INT)" Best Regards Tom Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted June 1, 2008 Author Share Posted June 1, 2008 thanks but still doesnt work now i get 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 '(INT), ipaddress VARCHAR(30), country VARCHAR(30), date VA thankyou anyway paul Quote Link to comment Share on other sites More sharing options...
trq Posted June 1, 2008 Share Posted June 1, 2008 date is a reserved word (or at least has special meanning in sql), choose another name. Quote Link to comment Share on other sites More sharing options...
AndyB Posted June 1, 2008 Share Posted June 1, 2008 mysql_query("CREATE TABLE example( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), score INT, ipaddress VARCHAR(30), country VARCHAR(30), date VARCHAR (30)") or die(mysql_error()); That works. Quote Link to comment Share on other sites More sharing options...
T Horton Posted June 1, 2008 Share Posted June 1, 2008 mysql_query(CREATE TABLE `example` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` VARCHAR( 30 ) NOT NULL , `score` INT, `ipaddress` VARCHAR( 30 ), `country` VARCHAR( 30 ), `date` VARCHAR (30)) or die (mysql_error()); This should work. Any probs, shout! Best Regards Tom Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted June 1, 2008 Author Share Posted June 1, 2008 nope that doesnt work. <?php mysql_query(CREATE TABLE `example` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` VARCHAR( 30 ) NOT NULL , `score` INT, `ipaddress` VARCHAR( 30 ), `country` VARCHAR( 30 ), `thedate` VARCHAR (30)) or die (mysql_error());?> I dont know why its not working. It comeing up with this Parse error: parse error, unexpected T_STRING in /home/www/mysite.com/install.php on line 7 Thankyou anyway Any more ideas Thankyou Paul Quote Link to comment Share on other sites More sharing options...
T Horton Posted June 1, 2008 Share Posted June 1, 2008 You have to assign each part to a string. So, for example: <?php $conn = mysql_connect("host", "user", "pass"); $db = mysql_select_db("database, $conn); ..... And so on. Now, for the query in question, you need to assign as follows: <?php $sql = mysql_query("CREATE TABLE `example` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` VARCHAR( 30 ) NOT NULL , `score` INT, `ipaddress` VARCHAR( 30 ), `country` VARCHAR( 30 ), `thedate` VARCHAR (30)") or die (mysql_error()); ?> What I would then do, to make sure it worked, would to: <?php if ($sql) { echo "Table Created"; } ?> Any closer? Best Regards Tom Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted June 1, 2008 Author Share Posted June 1, 2008 this was my old install file. <?php mysql_connect("host", "and", "so on") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("anything") or die(mysql_error()); echo "Connected to Database"; // Create a MySQL table in the selected database mysql_query("CREATE TABLE example( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), score INT)") or die(mysql_error()); echo "Table Created!"; ?> But i wanted to add date, ipaddress and country but i for some reason can't. Would it be easy to start a whole new script? Because for some reason none of us can get it working. Quote Link to comment Share on other sites More sharing options...
T Horton Posted June 1, 2008 Share Posted June 1, 2008 This is very funny. ??? Another suggestion: mysql_query("CREATE TABLE example ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30), score INT, ipaddress VARCHAR(30), country VARCHAR(30), date VARCHAR (30)") or die(mysql_error()); I can't think what else could be wrong with it. Let me know how you get on. Best Regards Tom Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted June 2, 2008 Author Share Posted June 2, 2008 ??? <?php mysql_connect("www.com", "ssss", "essss") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("huh") or die(mysql_error()); echo "Connected to Database"; // Create a MySQL table in the selected database mysql_query("CREATE TABLE myscore2 ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30), score INT, ipaddress VARCHAR(30), country VARCHAR(30), thedate VARCHAR (30)") or die(mysql_error()); echo "Table Created!"; ?> ??? Still not working and i have no idea why? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted June 2, 2008 Share Posted June 2, 2008 if you put your SQL into a variable and echo it out, you'll find it much easier to see the problem. Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted June 2, 2008 Author Share Posted June 2, 2008 so what shall i change? Quote Link to comment Share on other sites More sharing options...
runnerjp Posted June 2, 2008 Share Posted June 2, 2008 <?php mysql_connect("host", "and", "so on") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("anything") or die(mysql_error()); echo "Connected to Database"; // Create a MySQL table in the selected database $query=mysql_query("CREATE TABLE example( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), score INT)") or die(mysql_error()); echo $query; echo "Table Created!"; ?> do this and tell me what query echos Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted June 2, 2008 Share Posted June 2, 2008 no, i want to see the query, not the result of running it: $sql = "CREATE TABLE example( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), score INT)"; echo $sql; $query=mysql_query($sql) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
runnerjp Posted June 2, 2008 Share Posted June 2, 2008 sorry miss read Quote Link to comment Share on other sites More sharing options...
helraizer Posted June 2, 2008 Share Posted June 2, 2008 You put Primary Key in the wrong place: CREATE TABLE `myscore2` ( `id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR( 30 ) NOT NULL , `score` INT NOT NULL , `ipaddress` VARCHAR( 30 ) NOT NULL , `country` VARCHAR( 30 ) NOT NULL , `thedate` VARCHAR( 30 ) NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = MYISAM try that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.