...

View Full Version : multiple tables in one php



aconite
02-27-2007, 08:33 PM
i have a real wierd prob :'(
i have one file working.php which creates a database, selects it and then creates a table.another file drop.php drop that particular database.
first when i executed the working.php file, the database and table were created.then i dropped the database using drop.php.
then i made a few changes in working.php to create two more table. but now the same file wont give any output.
i am viewing the files in internet explorer.it gives absolutly no output. ???running drop.php gives the error
Error dropping database: Can't drop database 'mydatabase'; database doesn't exist
it makes sense since working.php is not working but wht should i do


working.php



<?php
$con = mysql_connect("127.0.0.1","root","12345");
if (!$con)
{
echo "Could not connect: ' . mysql_error();
}


if (mysql_query("CREATE DATABASE mydatabase",$con))
{
echo 'Database created ';
}
else
{
echo "Error creating database: " . mysql_error();
}


if(!mysql_select_db("mydatabase"))
{
die('Could not select database: mydatabase ' . mysql_error());
}

echo "Database selected ";

if (mysql_query("CREATE TABLE customer
(f_name VARCHAR(15) NOT NULL,
l_name VARCHAR(15) NOT NULL,
phone VARCHAR(11) ,
account INT UNSIGNED PRIMARY KEY)")
)
{
echo 'table created';
}
else
{
echo " Error creating table customer: " . mysql_error();
}
if (mysql_query("CREATE TABLE account
(account2 INT(7) UNSIGNED PRIMARY KEY,
password VARCHAR(4) NOT NULL,
balance FLOAT(3) ,
valid_till DATE YYYY-MM-DD)")
)
{
echo "created account table";
}
else
{
echo "account nt created " .mysql_error();
}

if (mysql_query("CREATE TABLE Transaction
(id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
source INT(7) UNSIGNED,
destination INT(7) UNSIGNED,
amount INT(3) NOT NULL,
date DATE YYYY-MM-DD,
strt_time TIME 00:00:00,
end_time TIME 00:00:00 ,
status ENUM("TRUE","FALSE") NOT NULL)")
)
{
echo("created transaction table";
}
else
{
echo "tran nt created " .mysql_error();
}

?>


drop.php

<?php
$con = mysql_connect("127.0.0.1","root","12345");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

echo '1 ';

if (mysql_query("DROP DATABASE mydatabase",$con))
{
echo 'Database dropped ';
}
else
{
echo "Error dropping database: " . mysql_error();
}
mysql_close($con);
?>


any idea what to do?im completely new and now lost



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum