[PHP] mysql_query pain!

Soldato
Joined
30 Jun 2003
Posts
2,807
Location
Berkshire
trying to get mysql enter the following data;

Code:
CREATE TABLE `servers` (
  `host` varchar(255) NOT NULL default '',
  `user` varchar(255) NOT NULL default '',
  `accesshash` text NOT NULL,
  PRIMARY KEY  (`host`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `users` (
  `ID` mediumint(9) NOT NULL auto_increment,
  `username` varchar(60) default NULL,
  `password` varchar(60) default NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

I'm doing each part seperately firstly the "servers" database i've done

Code:
 <?php
 require 'config.php';
mysql_query("CREATE TABLE `servers` (  `host` varchar(255) NOT NULL default '',  `user` varchar(255) NOT NULL default '',  `accesshash` text NOT NULL,  PRIMARY KEY  (`host`)))
 or die(mysql_error()");  
 
 ?>

config.php contains:

Code:
<?php
$connect = mysql_connect("HOST", "USER", "PASSWORD") or die(mysql_error());
$db = mysql_select_db("DATABASE") or die(mysql_error()); 
?>

Anyone got any suggestions on why this is not working?
 
Did you receive any error messages?

Put:
Code:
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

...at the top of your script if you're not.
 
A couple of quick questions:
I'm doing each part seperately firstly the "servers" database i've done.
Have you actually created a database called 'servers'? The create statement you're running will create a table, not a database.

And are you actually connecting to it correctly? Your config.php should look like (not sure if you've just substituted your details in what you posted):
Code:
<?php
$connect = mysql_connect("localhost", "uk_viper", "yourpass") or die(mysql_error());
$db = mysql_select_db("servers") or die(mysql_error()); 
?>
 
ok tried the error coding, firstly i forgot to put ../ infront of config.php however its still not adding the tables to the database
 
done it

Code:
 <?php
 error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
 require '../config.php';
mysql_query("CREATE TABLE `servers` (
  `host` varchar(255) NOT NULL default '',
  `user` varchar(255) NOT NULL default '',
  `accesshash` text NOT NULL,
  PRIMARY KEY  (`host`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1")
 or die(mysql_error()); 
 ?>
 
You realise you're not connecting to the database before trying to run a query? Unless it's in config.php, but that'd be a bit odd seeing as a connection isn't really config information.
 
Back
Top Bottom