Tjobbe
November 17th, 2004, 16:47
I have a database (mysql) and I'm trying to connect to it.
I'm using the exact format of a VTC training video, and I have used it before and it has worked, I've only created my own DB and can't understand why its not connecting:
my query.php file: Correct I think!
<?
$db = mysql_connect("localhost");
mysql_select_db("directory", $db);
$query = "SELECT * FROM directory";
$result = mysql_query($query);
$table = mysql_field_table ($result, 0);
echo $table;
?>
my database file:
(directory.sql)
# phpMyAdmin SQL Dump
# version 2.5.6
# http://www.phpmyadmin.net
#
# Host: localhost
# Generation Time: Nov 17, 2004 at 03:46 PM
# Server version: 4.0.18
# PHP Version: 4.3.6
#
# Database : `directory`
#
# --------------------------------------------------------
#
# Table structure for table `businesstype`
#
CREATE TABLE `businesstype` (
`businesstypeID` tinyint(3) unsigned NOT NULL auto_increment,
`name` varchar(20) NOT NULL default '',
PRIMARY KEY (`businesstypeID`)
) TYPE=MyISAM AUTO_INCREMENT=17 ;
#
# Dumping data for table `businesstype`
#
INSERT INTO `businesstype` VALUES (1, 'Web Design');
INSERT INTO `businesstype` VALUES (2, 'Packaging');
INSERT INTO `businesstype` VALUES (3, 'Art & Craft');
INSERT INTO `businesstype` VALUES (4, 'Accountancy');
INSERT INTO `businesstype` VALUES (5, 'Cleaning');
INSERT INTO `businesstype` VALUES (6, 'Manufacturing');
INSERT INTO `businesstype` VALUES (7, 'Engineering');
INSERT INTO `businesstype` VALUES (8, 'Transport');
INSERT INTO `businesstype` VALUES (9, 'Computing');
INSERT INTO `businesstype` VALUES (10, 'Managerial');
INSERT INTO `businesstype` VALUES (11, 'Recruitment');
INSERT INTO `businesstype` VALUES (12, 'Building');
INSERT INTO `businesstype` VALUES (13, 'Printing');
INSERT INTO `businesstype` VALUES (14, 'Acting');
INSERT INTO `businesstype` VALUES (15, 'Music, Film & T.V');
INSERT INTO `businesstype` VALUES (16, 'Banking');
# --------------------------------------------------------
#
# Table structure for table `busservices`
#
CREATE TABLE `busservices` (
`companyid` tinyint(3) unsigned NOT NULL default '0',
`businesstypeID` tinyint(3) unsigned NOT NULL default '0'
) TYPE=MyISAM;
#
# Dumping data for table `busservices`
#
INSERT INTO `busservices` VALUES (1, 1);
INSERT INTO `busservices` VALUES (1, 2);
INSERT INTO `busservices` VALUES (1, 3);
INSERT INTO `busservices` VALUES (1, 5);
INSERT INTO `busservices` VALUES (1, 7);
INSERT INTO `busservices` VALUES (1, 11);
INSERT INTO `busservices` VALUES (2, 1);
INSERT INTO `busservices` VALUES (2, 3);
INSERT INTO `busservices` VALUES (2, 5);
INSERT INTO `busservices` VALUES (2, 6);
INSERT INTO `busservices` VALUES (2, 7);
INSERT INTO `busservices` VALUES (2, 8);
INSERT INTO `busservices` VALUES (2, 9);
INSERT INTO `busservices` VALUES (2, 11);
INSERT INTO `busservices` VALUES (3, 3);
INSERT INTO `busservices` VALUES (3, 4);
INSERT INTO `busservices` VALUES (3, 7);
INSERT INTO `busservices` VALUES (3, 9);
INSERT INTO `busservices` VALUES (3, 13);
INSERT INTO `busservices` VALUES (3, 14);
INSERT INTO `busservices` VALUES (4, 1);
INSERT INTO `busservices` VALUES (4, 2);
INSERT INTO `busservices` VALUES (4, 5);
INSERT INTO `busservices` VALUES (4, 6);
INSERT INTO `busservices` VALUES (4, 3);
INSERT INTO `busservices` VALUES (4, 8);
INSERT INTO `busservices` VALUES (5, 3);
INSERT INTO `busservices` VALUES (5, 4);
INSERT INTO `busservices` VALUES (5, 7);
INSERT INTO `busservices` VALUES (5, 9);
INSERT INTO `busservices` VALUES (5, 10);
INSERT INTO `busservices` VALUES (5, 14);
INSERT INTO `busservices` VALUES (6, 4);
INSERT INTO `busservices` VALUES (6, 10);
INSERT INTO `busservices` VALUES (2, 15);
INSERT INTO `busservices` VALUES (2, 10);
INSERT INTO `busservices` VALUES (7, 1);
INSERT INTO `busservices` VALUES (7, 2);
INSERT INTO `busservices` VALUES (7, 6);
INSERT INTO `busservices` VALUES (8, 1);
INSERT INTO `busservices` VALUES (8, 3);
INSERT INTO `busservices` VALUES (8, 7);
INSERT INTO `busservices` VALUES (8, 2);
INSERT INTO `busservices` VALUES (8, 12);
INSERT INTO `busservices` VALUES (9, 6);
INSERT INTO `busservices` VALUES (9, 15);
INSERT INTO `busservices` VALUES (10, 10);
INSERT INTO `busservices` VALUES (10, 5);
INSERT INTO `busservices` VALUES (10, 11);
INSERT INTO `busservices` VALUES (10, 3);
INSERT INTO `busservices` VALUES (10, 9);
INSERT INTO `busservices` VALUES (3, 16);
INSERT INTO `busservices` VALUES (5, 16);
# --------------------------------------------------------
#
# Table structure for table `companydetails`
#
CREATE TABLE `companydetails` (
`companyid` tinyint(3) unsigned NOT NULL auto_increment,
`busname` varchar(40) NOT NULL default '',
`address1` varchar(40) default NULL,
`address2` varchar(40) default NULL,
`town` varchar(40) default NULL,
`county` varchar(40) NOT NULL default '',
`postcode` varchar(40) NOT NULL default '',
`phone` varchar(18) NOT NULL default '',
`fax` varchar(18) NOT NULL default '',
`email` varchar(60) NOT NULL default '',
`website` varchar(60) NOT NULL default '',
`comments` varchar(80) NOT NULL default '',
PRIMARY KEY (`companyid`)
) TYPE=MyISAM AUTO_INCREMENT=11 ;
#
# Dumping data for table `companydetails`
#
INSERT INTO `companydetails` VALUES (1, 'Bleep Bleep Records', '14 Industrial Ave', 'Main Road', 'Troughton', '', 'PL25 3AR', '65465465', '64351231', 'bleepbleep@freeemail.com', '', 'Interesting UV-glow clubwear also on sale');
INSERT INTO `companydetails` VALUES (2, 'Hi Fly Sounds', '15 Outersdale Road', '', 'Imblendon', '', '', '64231615', '', 'hiflier@hotmail.com', '', '');
INSERT INTO `companydetails` VALUES (3, 'Tuff Tune', '13 Yard St', '', 'Troughton', '', '', '64321654', '64351684', 'tufftune@yahoo.com', '', 'Specialist t\'ing ..');
INSERT INTO `companydetails` VALUES (4, 'Deeper Beat Records', '53 Blempton Ave', '', 'Durringvale', '', '', '64231654', '64615644', 'info@deeperbeat.com.au', 'www.deeperbeat.com.au', '');
INSERT INTO `companydetails` VALUES (5, 'Riddim Records', '37 Dorset Road', '', 'Hellington', '', '', '64234516', '', 'manager@riddim.com.au', 'www.riddim.com.au', 'Rudeboy riddims');
INSERT INTO `companydetails` VALUES (6, 'Phat Bass Music', '91 Bevelled Road', 'Long Park', 'Sirdale', '', '', '64321684', '64351568', 'phatbass@mymail.com', '', 'Loud flavas');
INSERT INTO `companydetails` VALUES (7, 'Minimalism', '24 Crane St', '', 'Hellington', '', '', '64321684', '64321684', 'us@minimalism.com.au', 'www.minimalism.com.au', 'Seriously stripped-down techno');
INSERT INTO `companydetails` VALUES (8, 'Explosive Records', '71 Bang St', '', 'Troughton', '', '', '64321684', '64651684', 'bang@hotmail.com', '', '');
INSERT INTO `companydetails` VALUES (9, 'Fab Sounds', '21 Enders Lane', '', 'Imbledon', '', '', '64231654', '64654651', 'tony@fabsound.com.au', 'www.fabsound.com.au', 'Gorgeous toons daarling!');
INSERT INTO `companydetails` VALUES (10, 'Freaky Beat', '85 Ungoliant Ave', 'Wyrd Hills', 'Trippiton', '', '', '64321654', '', 'str@oddside.com.au', '', 'Very, very odd.');
I'm really really confused! :o
I'm using the exact format of a VTC training video, and I have used it before and it has worked, I've only created my own DB and can't understand why its not connecting:
my query.php file: Correct I think!
<?
$db = mysql_connect("localhost");
mysql_select_db("directory", $db);
$query = "SELECT * FROM directory";
$result = mysql_query($query);
$table = mysql_field_table ($result, 0);
echo $table;
?>
my database file:
(directory.sql)
# phpMyAdmin SQL Dump
# version 2.5.6
# http://www.phpmyadmin.net
#
# Host: localhost
# Generation Time: Nov 17, 2004 at 03:46 PM
# Server version: 4.0.18
# PHP Version: 4.3.6
#
# Database : `directory`
#
# --------------------------------------------------------
#
# Table structure for table `businesstype`
#
CREATE TABLE `businesstype` (
`businesstypeID` tinyint(3) unsigned NOT NULL auto_increment,
`name` varchar(20) NOT NULL default '',
PRIMARY KEY (`businesstypeID`)
) TYPE=MyISAM AUTO_INCREMENT=17 ;
#
# Dumping data for table `businesstype`
#
INSERT INTO `businesstype` VALUES (1, 'Web Design');
INSERT INTO `businesstype` VALUES (2, 'Packaging');
INSERT INTO `businesstype` VALUES (3, 'Art & Craft');
INSERT INTO `businesstype` VALUES (4, 'Accountancy');
INSERT INTO `businesstype` VALUES (5, 'Cleaning');
INSERT INTO `businesstype` VALUES (6, 'Manufacturing');
INSERT INTO `businesstype` VALUES (7, 'Engineering');
INSERT INTO `businesstype` VALUES (8, 'Transport');
INSERT INTO `businesstype` VALUES (9, 'Computing');
INSERT INTO `businesstype` VALUES (10, 'Managerial');
INSERT INTO `businesstype` VALUES (11, 'Recruitment');
INSERT INTO `businesstype` VALUES (12, 'Building');
INSERT INTO `businesstype` VALUES (13, 'Printing');
INSERT INTO `businesstype` VALUES (14, 'Acting');
INSERT INTO `businesstype` VALUES (15, 'Music, Film & T.V');
INSERT INTO `businesstype` VALUES (16, 'Banking');
# --------------------------------------------------------
#
# Table structure for table `busservices`
#
CREATE TABLE `busservices` (
`companyid` tinyint(3) unsigned NOT NULL default '0',
`businesstypeID` tinyint(3) unsigned NOT NULL default '0'
) TYPE=MyISAM;
#
# Dumping data for table `busservices`
#
INSERT INTO `busservices` VALUES (1, 1);
INSERT INTO `busservices` VALUES (1, 2);
INSERT INTO `busservices` VALUES (1, 3);
INSERT INTO `busservices` VALUES (1, 5);
INSERT INTO `busservices` VALUES (1, 7);
INSERT INTO `busservices` VALUES (1, 11);
INSERT INTO `busservices` VALUES (2, 1);
INSERT INTO `busservices` VALUES (2, 3);
INSERT INTO `busservices` VALUES (2, 5);
INSERT INTO `busservices` VALUES (2, 6);
INSERT INTO `busservices` VALUES (2, 7);
INSERT INTO `busservices` VALUES (2, 8);
INSERT INTO `busservices` VALUES (2, 9);
INSERT INTO `busservices` VALUES (2, 11);
INSERT INTO `busservices` VALUES (3, 3);
INSERT INTO `busservices` VALUES (3, 4);
INSERT INTO `busservices` VALUES (3, 7);
INSERT INTO `busservices` VALUES (3, 9);
INSERT INTO `busservices` VALUES (3, 13);
INSERT INTO `busservices` VALUES (3, 14);
INSERT INTO `busservices` VALUES (4, 1);
INSERT INTO `busservices` VALUES (4, 2);
INSERT INTO `busservices` VALUES (4, 5);
INSERT INTO `busservices` VALUES (4, 6);
INSERT INTO `busservices` VALUES (4, 3);
INSERT INTO `busservices` VALUES (4, 8);
INSERT INTO `busservices` VALUES (5, 3);
INSERT INTO `busservices` VALUES (5, 4);
INSERT INTO `busservices` VALUES (5, 7);
INSERT INTO `busservices` VALUES (5, 9);
INSERT INTO `busservices` VALUES (5, 10);
INSERT INTO `busservices` VALUES (5, 14);
INSERT INTO `busservices` VALUES (6, 4);
INSERT INTO `busservices` VALUES (6, 10);
INSERT INTO `busservices` VALUES (2, 15);
INSERT INTO `busservices` VALUES (2, 10);
INSERT INTO `busservices` VALUES (7, 1);
INSERT INTO `busservices` VALUES (7, 2);
INSERT INTO `busservices` VALUES (7, 6);
INSERT INTO `busservices` VALUES (8, 1);
INSERT INTO `busservices` VALUES (8, 3);
INSERT INTO `busservices` VALUES (8, 7);
INSERT INTO `busservices` VALUES (8, 2);
INSERT INTO `busservices` VALUES (8, 12);
INSERT INTO `busservices` VALUES (9, 6);
INSERT INTO `busservices` VALUES (9, 15);
INSERT INTO `busservices` VALUES (10, 10);
INSERT INTO `busservices` VALUES (10, 5);
INSERT INTO `busservices` VALUES (10, 11);
INSERT INTO `busservices` VALUES (10, 3);
INSERT INTO `busservices` VALUES (10, 9);
INSERT INTO `busservices` VALUES (3, 16);
INSERT INTO `busservices` VALUES (5, 16);
# --------------------------------------------------------
#
# Table structure for table `companydetails`
#
CREATE TABLE `companydetails` (
`companyid` tinyint(3) unsigned NOT NULL auto_increment,
`busname` varchar(40) NOT NULL default '',
`address1` varchar(40) default NULL,
`address2` varchar(40) default NULL,
`town` varchar(40) default NULL,
`county` varchar(40) NOT NULL default '',
`postcode` varchar(40) NOT NULL default '',
`phone` varchar(18) NOT NULL default '',
`fax` varchar(18) NOT NULL default '',
`email` varchar(60) NOT NULL default '',
`website` varchar(60) NOT NULL default '',
`comments` varchar(80) NOT NULL default '',
PRIMARY KEY (`companyid`)
) TYPE=MyISAM AUTO_INCREMENT=11 ;
#
# Dumping data for table `companydetails`
#
INSERT INTO `companydetails` VALUES (1, 'Bleep Bleep Records', '14 Industrial Ave', 'Main Road', 'Troughton', '', 'PL25 3AR', '65465465', '64351231', 'bleepbleep@freeemail.com', '', 'Interesting UV-glow clubwear also on sale');
INSERT INTO `companydetails` VALUES (2, 'Hi Fly Sounds', '15 Outersdale Road', '', 'Imblendon', '', '', '64231615', '', 'hiflier@hotmail.com', '', '');
INSERT INTO `companydetails` VALUES (3, 'Tuff Tune', '13 Yard St', '', 'Troughton', '', '', '64321654', '64351684', 'tufftune@yahoo.com', '', 'Specialist t\'ing ..');
INSERT INTO `companydetails` VALUES (4, 'Deeper Beat Records', '53 Blempton Ave', '', 'Durringvale', '', '', '64231654', '64615644', 'info@deeperbeat.com.au', 'www.deeperbeat.com.au', '');
INSERT INTO `companydetails` VALUES (5, 'Riddim Records', '37 Dorset Road', '', 'Hellington', '', '', '64234516', '', 'manager@riddim.com.au', 'www.riddim.com.au', 'Rudeboy riddims');
INSERT INTO `companydetails` VALUES (6, 'Phat Bass Music', '91 Bevelled Road', 'Long Park', 'Sirdale', '', '', '64321684', '64351568', 'phatbass@mymail.com', '', 'Loud flavas');
INSERT INTO `companydetails` VALUES (7, 'Minimalism', '24 Crane St', '', 'Hellington', '', '', '64321684', '64321684', 'us@minimalism.com.au', 'www.minimalism.com.au', 'Seriously stripped-down techno');
INSERT INTO `companydetails` VALUES (8, 'Explosive Records', '71 Bang St', '', 'Troughton', '', '', '64321684', '64651684', 'bang@hotmail.com', '', '');
INSERT INTO `companydetails` VALUES (9, 'Fab Sounds', '21 Enders Lane', '', 'Imbledon', '', '', '64231654', '64654651', 'tony@fabsound.com.au', 'www.fabsound.com.au', 'Gorgeous toons daarling!');
INSERT INTO `companydetails` VALUES (10, 'Freaky Beat', '85 Ungoliant Ave', 'Wyrd Hills', 'Trippiton', '', '', '64321654', '', 'str@oddside.com.au', '', 'Very, very odd.');
I'm really really confused! :o