Nightwalker83
Feb 20th, 2010, 12:27 AM
Hi,
I'm using code I have used before to create a database! While I can create the database for some reason it won't allow me to create the table. This is the code I am using to create the database:
<?php
//connect to server or exit
require_once("php/conroot.php");
//create database
$query = "CREATE DATABASE IF NOT EXISTS $dbDatabase";
if (mysql_query($query, $conn)) {
echo ("Database create query successful");
}
//select database
if (mysql_select_db($dbDatabase, $conn)) {
echo ("Database selection successful");
}else {
die ("Could not locate $dbDatabase database" .mysql_error());
}
//create table
$query = "CREATE TABLE IF NOT EXISTS $table (
'id' int(2) NOT NULL auto_increment unique,
'Nameochild' varchar(30) default NULL,
'Address' varchar(30) default NULL,
'Email' varchar(50) default NULL,
'Mobile' varchar(20) default NULL,
'Postcode' varchar(6) default NULL,
DOB' varchar(20) default NULL,
'Phone' varchar(10) default NULL,
'Medical' varchar(100) default NULL,
'Photo' varchar(1) default NULL,
'Guardian' varchar(20) default NULL,
'Date'(8) default NULL,
PRIMARY KEY ('id')
) TYPE=MyISAM";
if (mysql_query($query, $conn)) {
echo ("table $table query successful");
}
?>
Edit:
Here is the code for conroot.php:
<?php
//connect to db
$conn = mysql_connect("localhost", "root", "");
if (!$conn) {
die("Connection failed: " .mysql_error());
}
// Database connection variables
$dbDatabase = "database";
$table = "table";
?>
Have I missed anything? I have looked over the code and cant see anything that might be wrong.
Thanks,
Nightwalker
I'm using code I have used before to create a database! While I can create the database for some reason it won't allow me to create the table. This is the code I am using to create the database:
<?php
//connect to server or exit
require_once("php/conroot.php");
//create database
$query = "CREATE DATABASE IF NOT EXISTS $dbDatabase";
if (mysql_query($query, $conn)) {
echo ("Database create query successful");
}
//select database
if (mysql_select_db($dbDatabase, $conn)) {
echo ("Database selection successful");
}else {
die ("Could not locate $dbDatabase database" .mysql_error());
}
//create table
$query = "CREATE TABLE IF NOT EXISTS $table (
'id' int(2) NOT NULL auto_increment unique,
'Nameochild' varchar(30) default NULL,
'Address' varchar(30) default NULL,
'Email' varchar(50) default NULL,
'Mobile' varchar(20) default NULL,
'Postcode' varchar(6) default NULL,
DOB' varchar(20) default NULL,
'Phone' varchar(10) default NULL,
'Medical' varchar(100) default NULL,
'Photo' varchar(1) default NULL,
'Guardian' varchar(20) default NULL,
'Date'(8) default NULL,
PRIMARY KEY ('id')
) TYPE=MyISAM";
if (mysql_query($query, $conn)) {
echo ("table $table query successful");
}
?>
Edit:
Here is the code for conroot.php:
<?php
//connect to db
$conn = mysql_connect("localhost", "root", "");
if (!$conn) {
die("Connection failed: " .mysql_error());
}
// Database connection variables
$dbDatabase = "database";
$table = "table";
?>
Have I missed anything? I have looked over the code and cant see anything that might be wrong.
Thanks,
Nightwalker