[SOLVED] PHP Creat tables in MySQL

This is a discussion on "[SOLVED] PHP Creat tables in MySQL" within the PHP Forum section. This forum, and the thread "[SOLVED] PHP Creat tables in MySQL are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 21st, 2008, 12:14
Emzi's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Manchester
Age: 25
Posts: 148
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] PHP Creat tables in MySQL

Hey all,

I'm trying to create a script for users to go to an install page and click "install" and it will create tables in their database (which they've already provided information for).

At the moment in the PHP code I've written it so it will create two database tables. The problem is it will only create one of them. And bizzarly it installs the table that comes second ('tblAPPLIED').

Here's my code:

PHP: Select all

<?
@mysql_select_db($database_ukjobsite) or die( "Unable to select database");
 
$query "CREATE TABLE `tblADMIN` (
  `admin_id` int(11) NOT NULL auto_increment,
  `admin_username` varchar(25) collate utf8_unicode_ci NOT NULL,
  `admin_password` varchar(25) collate utf8_unicode_ci NOT NULL,
  `admin_level` int(11) NOT NULL default '0',
  PRIMARY KEY  (`admin_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2"
;
 
$query "CREATE TABLE `tblAPPLIED` (
  `applied_id` int(11) NOT NULL auto_increment,
  `first_name` varchar(50) character set utf8 collate utf8_unicode_ci NOT NULL,
  `last_name` varchar(50) character set utf8 collate utf8_unicode_ci NOT NULL,
  `region_id` smallint(5) NOT NULL,
  `telephone` varchar(25) character set utf8 collate utf8_unicode_ci NOT NULL,
  `covernote` text character set utf8 collate utf8_unicode_ci NOT NULL,
  `cv_filename` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
  `date_applied` int(11) NOT NULL default '0',
  PRIMARY KEY  (`applied_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1"
;
 
mysql_query($query);
mysql_close();
?>
Does anyone know where I'm going wrong? Thanks in advance!
Reply With Quote

  #2 (permalink)  
Old Jan 21st, 2008, 12:21
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP Creat tables in MySQL

It's because you are resetting the query.... You set the query text and then overwrite it.

add a semi colon to the end of the first query and then start the second query with the concatenation operator.

....etc etc AUTO_INCREMENT=2;";

$query .= 'etc';
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #3 (permalink)  
Old Jan 21st, 2008, 12:31
Emzi's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Manchester
Age: 25
Posts: 148
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP Creat tables in MySQL

Hi, thanks for that, but it still didn't work.

This is what I have now:

PHP: Select all

$query "CREATE TABLE `tblADMIN` (
  `admin_id` int(11) NOT NULL auto_increment,
  `admin_username` varchar(25) collate utf8_unicode_ci NOT NULL,
  `admin_password` varchar(25) collate utf8_unicode_ci NOT NULL,
  `admin_level` int(11) NOT NULL default '0',
  PRIMARY KEY  (`admin_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2;"
;
 
$query .= "CREATE TABLE `tblAPPLIED` (
  `applied_id` int(11) NOT NULL auto_increment,
  `first_name` varchar(50) character set utf8 collate utf8_unicode_ci NOT NULL,
  `last_name` varchar(50) character set utf8 collate utf8_unicode_ci NOT NULL,
  `region_id` smallint(5) NOT NULL,
  `telephone` varchar(25) character set utf8 collate utf8_unicode_ci NOT NULL,
  `covernote` text character set utf8 collate utf8_unicode_ci NOT NULL,
  `cv_filename` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
  `date_applied` int(11) NOT NULL default '0',
  PRIMARY KEY  (`applied_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1"
;
 
 
mysql_query($query);
mysql_close(); 
Any ideas what I did wrong? Thanks
Reply With Quote
  #4 (permalink)  
Old Jan 21st, 2008, 12:36
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP Creat tables in MySQL

Why don't you just run it as two queries?

PHP: Select all

$query "CREATE TABLE `tblADMIN` (

  `admin_id` int(11) NOT NULL auto_increment,
  `admin_username` varchar(25) collate utf8_unicode_ci NOT NULL,
  `admin_password` varchar(25) collate utf8_unicode_ci NOT NULL,
  `admin_level` int(11) NOT NULL default '0',
  PRIMARY KEY  (`admin_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2"
;

 
mysql_query($query);


$query "CREATE TABLE `tblAPPLIED` (
  `applied_id` int(11) NOT NULL auto_increment,
  `first_name` varchar(50) character set utf8 collate utf8_unicode_ci NOT NULL,
  `last_name` varchar(50) character set utf8 collate utf8_unicode_ci NOT NULL,
  `region_id` smallint(5) NOT NULL,
  `telephone` varchar(25) character set utf8 collate utf8_unicode_ci NOT NULL,
  `covernote` text character set utf8 collate utf8_unicode_ci NOT NULL,
  `cv_filename` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
  `date_applied` int(11) NOT NULL default '0',
  PRIMARY KEY  (`applied_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1"
;
 
 
mysql_query($query);
mysql_close(); 
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #5 (permalink)  
Old Jan 21st, 2008, 12:41
Emzi's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Manchester
Age: 25
Posts: 148
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP Creat tables in MySQL

To be honest, I'm still not 100% at this and I seem to be ok at the more complex stuff, but the simple stuff is beyond me

But thanks, what you suggested worked So thanks!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How do I creat a popup/tool tip without using JS Oak Web Page Design 4 Dec 17th, 2007 10:41
Dropping tables in MySQL Daniel Databases 12 Jul 19th, 2007 12:58
Displaying MySQL database tables on a page vandiermen PHP Forum 3 Jun 30th, 2007 21:58
Country, postcode etc - mysql tables jimz Databases 2 Jan 30th, 2007 17:02


All times are GMT. The time now is 02:04.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43