xProteuSx Posted November 13, 2006 Share Posted November 13, 2006 I am very new to php/MySQL so I am playing around with the basic functions and I cannot get the DROP TABLE statement to work. My code is as follows:[code]<?php$sql = "DROP TABLE usersCREATE TABLE users (users_id int(6) NOT NULL auto_increment,users_handle varchar(20) default NULL,users_password varchar (20) default NULL,users_email varchar (40) default NULL,users_datejoined timestamp NOT NULL,users_visits int (6) default '0',users_lastvisit timestamp NOT NULL,users_questionsanswered int(6) default '0',users_correctanswers int(6) default '0',users_percentcorrect float default '0',users_totalscore int (6) default '0',users_pagesviewed int(8) default '0',users_visitbonus int(6) default '0',users_activity int(6) default '0',PRIMARY KEY(users_id),UNIQUE(users_handle)) TYPE=MYISAM;"?>[/code]What I am trying to do is to drop the previous 'users' table and create a new one in its place. I tried everything I can think of, I believe, including "DROP TABLE users;" I don't know what to do anymore. Some help would be duly appreciated. Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/27071-cannot-drop-table/ Share on other sites More sharing options...
btherl Posted November 13, 2006 Share Posted November 13, 2006 You will certainly need a ";" at the end of the drop table, eg "DROP TABLE users;"It might be better to do two seperate queries, one to drop the table and one to create the table. That will make error handling much simpler. Quote Link to comment https://forums.phpfreaks.com/topic/27071-cannot-drop-table/#findComment-123812 Share on other sites More sharing options...
xProteuSx Posted November 13, 2006 Author Share Posted November 13, 2006 When I add the ';' this is the error that I get: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 '; CREATE TABLE users ( users_id int(6) NOT NULL auto_incremenYou're absolutely right about two queries, however. The problem is, I am unsure of how to do two separate queries. I will try the following:[code]<?php$sql = "DROP TABLE users";$sql = "CREATE TABLE users (users_id int(6) NOT NULL auto_increment,users_handle varchar(20) default NULL,users_password varchar (20) default NULL,users_email varchar (40) default NULL,users_datejoined timestamp NOT NULL,users_visits int (6) default '0',users_lastvisit timestamp NOT NULL,users_questionsanswered int(6) default '0',users_correctanswers int(6) default '0',users_percentcorrect float default '0',users_totalscore int (6) default '0',users_pagesviewed int(8) default '0',users_visitbonus int(6) default '0',users_activity int(6) default '0',PRIMARY KEY(users_id),UNIQUE(users_handle)) TYPE=MYISAM;"?>[/code]Does that seem correct? Thanks a bunch. Quote Link to comment https://forums.phpfreaks.com/topic/27071-cannot-drop-table/#findComment-123813 Share on other sites More sharing options...
xProteuSx Posted November 13, 2006 Author Share Posted November 13, 2006 Must not be correct, because it did not work ... Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/27071-cannot-drop-table/#findComment-123814 Share on other sites More sharing options...
btherl Posted November 13, 2006 Share Posted November 13, 2006 Is that your whole code right there? That won't do anything :)[code=php:0]$sql = "DROP TABLE users";$result = mysql_query($sql) or die("Error on $sql: " . mysql_error());[/code]You will also need to connect to the database first using mysql_connect(), using the information given by your hosting provider. Quote Link to comment https://forums.phpfreaks.com/topic/27071-cannot-drop-table/#findComment-123820 Share on other sites More sharing options...
xProteuSx Posted November 13, 2006 Author Share Posted November 13, 2006 Well, if you are worried that the code is not connecting to the MySQL server then rest assured that the connection is fine, but I have not included the connection code in this snippet. I know that the connection is good because if I manually drop the table via phpMySQLadmin and run this code, it does generate a users table. I just can't seem to get the DROP command to work. Quote Link to comment https://forums.phpfreaks.com/topic/27071-cannot-drop-table/#findComment-123833 Share on other sites More sharing options...
.josh Posted November 13, 2006 Share Posted November 13, 2006 he wasn't providing you with a connection script. he was providing you with the php function to actually run your query. Quote Link to comment https://forums.phpfreaks.com/topic/27071-cannot-drop-table/#findComment-123834 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.