daled Posted July 14, 2007 Share Posted July 14, 2007 i've got a problem (so does everybody else). anyways. php won't execute this query for me: <?php $query = sprintf("CREATE DATABASE `$dbname` -- -- Table structure for table 'addressbook' -- CREATE TABLE IF NOT EXISTS `addressbook` ( `team` varchar(255) NOT NULL default '', `number` mediumint(9) NOT NULL auto_increment, PRIMARY KEY (number) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'albums' -- CREATE TABLE IF NOT EXISTS `albums` ( `album` varchar(255) NOT NULL default '', `number` smallint(6) NOT NULL auto_increment, `description` longtext NOT NULL, `thumbnail` varchar(255) NOT NULL default '', PRIMARY KEY (number) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'basicinfo' -- CREATE TABLE IF NOT EXISTS `basicinfo` ( `bandname` varchar(255) NOT NULL default '', `bio` longtext NOT NULL, `genre` varchar(255) NOT NULL default '', `avatar` varchar(255) NOT NULL default '' ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'comments' -- CREATE TABLE IF NOT EXISTS `comments` ( `number` smallint(6) NOT NULL auto_increment, `poster` varchar(255) NOT NULL default '', `IP` varchar(255) NOT NULL default '', `time` varchar(255) NOT NULL default '', `date` varchar(255) NOT NULL default '', `comment` longtext NOT NULL, PRIMARY KEY (number) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'dates' -- CREATE TABLE IF NOT EXISTS `dates` ( `number` smallint(6) NOT NULL auto_increment, `date` varchar(255) NOT NULL default '', `time` varchar(255) NOT NULL default '', `venue` varchar(255) NOT NULL default '', `city` varchar(255) NOT NULL default '', `state` varchar(255) NOT NULL default '', `price` varchar(255) NOT NULL default '', `venuesite` mediumtext NOT NULL, PRIMARY KEY (number) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'feature' -- CREATE TABLE IF NOT EXISTS `feature` ( `albumnumber` varchar(255) NOT NULL default '', `album` varchar(255) default NULL, `1` varchar(255) default NULL, `2` varchar(255) default NULL, `3` varchar(255) default NULL, `4` varchar(255) default NULL, `5` varchar(255) default NULL ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'inbox' -- CREATE TABLE IF NOT EXISTS `inbox` ( `sender` varchar(255) NOT NULL default '', `time` varchar(255) NOT NULL default '', `message` varchar(255) NOT NULL default '', `number` mediumint(9) NOT NULL auto_increment, PRIMARY KEY (number) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'journal' -- CREATE TABLE IF NOT EXISTS `journal` ( `number` smallint(6) NOT NULL auto_increment, `title` varchar(255) NOT NULL default '', `time` varchar(255) NOT NULL default '', `date` varchar(255) NOT NULL default '', `journal` longtext NOT NULL, PRIMARY KEY (number) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'members' -- CREATE TABLE IF NOT EXISTS `members` ( `number` smallint(6) NOT NULL auto_increment, `name` varchar(255) NOT NULL default '', `instrument` varchar(255) NOT NULL default '', PRIMARY KEY (number) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'pictures' -- CREATE TABLE IF NOT EXISTS `pictures` ( `number` smallint(6) NOT NULL auto_increment, `url` varchar(255) NOT NULL default '', `description` longtext NOT NULL, PRIMARY KEY (number) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'requests' -- CREATE TABLE IF NOT EXISTS `requests` ( `number` smallint(6) NOT NULL auto_increment, `name` varchar(255) NOT NULL default '', `city` varchar(255) NOT NULL default '', `state` varchar(255) NOT NULL default '', `notes` longtext NOT NULL, PRIMARY KEY (number) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'sentmessages' -- CREATE TABLE IF NOT EXISTS `sentmessages` ( `recipient` varchar(255) NOT NULL default '', `time` varchar(255) NOT NULL default '', `message` varchar(255) NOT NULL default '', `number` mediumint(9) NOT NULL auto_increment, PRIMARY KEY (number) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table 'songs' -- CREATE TABLE IF NOT EXISTS `songs` ( `number` smallint(6) NOT NULL auto_increment, `song` varchar(255) NOT NULL default '', `album` varchar(255) NOT NULL default '', `albumnumber` varchar(255) NOT NULL default '', `genre` varchar(255) NOT NULL default '', `url` varchar(255) NOT NULL default '', PRIMARY KEY (number) ) TYPE=MyISAM;"); $db = mysql_query($query, $register); ?> I don't get any errors (php or mysql), it just won't do it. i simply ignores it and continues. what's up with that? Link to comment https://forums.phpfreaks.com/topic/60010-solved-queries-using-php/ Share on other sites More sharing options...
pocobueno1388 Posted July 14, 2007 Share Posted July 14, 2007 You can't have all those "--" and comments in the query. Also, it helps if you try to catch the error like this: $db = mysql_query($query, $register)or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/60010-solved-queries-using-php/#findComment-298463 Share on other sites More sharing options...
daled Posted July 14, 2007 Author Share Posted July 14, 2007 phpMyAdmin gives me this: #1064 - 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 `addressbook` ( `band` varchar(255) NOT NULL Link to comment https://forums.phpfreaks.com/topic/60010-solved-queries-using-php/#findComment-298471 Share on other sites More sharing options...
Barand Posted July 14, 2007 Share Posted July 14, 2007 You need to execute each create query seperately with mysql_query Link to comment https://forums.phpfreaks.com/topic/60010-solved-queries-using-php/#findComment-298479 Share on other sites More sharing options...
rameshfaj Posted July 15, 2007 Share Posted July 15, 2007 $query="CREATE TABLE IF NOT EXISTS `addressbook` ( `team` varchar(255) NOT NULL default '', `number` mediumint(9) NOT NULL auto_increment, PRIMARY KEY (number) )"; I tried this query in mysql 4 and it did execute successfully.Then what's the problem? Link to comment https://forums.phpfreaks.com/topic/60010-solved-queries-using-php/#findComment-298607 Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 it did execute successfully. I am going to assume you meant didn't. Try catching the error: $query="CREATE TABLE IF NOT EXISTS `addressbook` ( `team` varchar(255) NOT NULL default '', `number` mediumint(9) NOT NULL auto_increment, PRIMARY KEY (number) ); $try_query = mysql_query($query)or die(mysql_error()); Here is the syntax for creating a table: http://dev.mysql.com/doc/refman/5.0/en/create-table.html Link to comment https://forums.phpfreaks.com/topic/60010-solved-queries-using-php/#findComment-298609 Share on other sites More sharing options...
rameshfaj Posted July 15, 2007 Share Posted July 15, 2007 Have a look at the snapshot and then tell me whats the matters. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/60010-solved-queries-using-php/#findComment-298629 Share on other sites More sharing options...
trq Posted July 15, 2007 Share Posted July 15, 2007 Have a look at the snapshot and then tell me whats the matters. Have you got a question or what? Vague commentary is getting you nowhere. Link to comment https://forums.phpfreaks.com/topic/60010-solved-queries-using-php/#findComment-298631 Share on other sites More sharing options...
rameshfaj Posted July 15, 2007 Share Posted July 15, 2007 Sorry for that !!! But I just wanted to show that the sql query was executing.None others. If something wrong occured then I apologize for that. Link to comment https://forums.phpfreaks.com/topic/60010-solved-queries-using-php/#findComment-298636 Share on other sites More sharing options...
trq Posted July 15, 2007 Share Posted July 15, 2007 Yeah... that query would more likely execute without problem within the mysql client. However, as has been pointed out already, mysql_query() can only execute one query at a time. Link to comment https://forums.phpfreaks.com/topic/60010-solved-queries-using-php/#findComment-298639 Share on other sites More sharing options...
daled Posted July 15, 2007 Author Share Posted July 15, 2007 i didn't know that mysql query could only execute on query at a time. well, putting in each query seperately worked. problem solved! thanks! Link to comment https://forums.phpfreaks.com/topic/60010-solved-queries-using-php/#findComment-298991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.