Jump to content

[SOLVED] multiple tables in one php file???


aconite

Recommended Posts

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

Link to comment
Share on other sites

i executed this code

<?php

echo '1  ';

$con = mysql_connect("127.0.0.1:3306","root","12345");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

echo '1  ';

 

?>

 

gives the output

1 1

so a simple connection works fine.but still ahving problem with the working.php file ???

Link to comment
Share on other sites

i pasted each block ,one by one.first two tables are created successfully :) the prob is in

if (mysql_query("CREATE TABLE transaction

                              (id INT(4) AUTO_INCREMENT NOT NULL PRIMARY KEY,

      source INT(7) UNSIGNED,

                              destination  INT(7) UNSIGNED,

                              amount INT(3) NOT NULL,

                              date DATE ,

      strt_time TIME ,

                              end_time  TIME ,

                              status ENUM("TRUE","FALSE") NOT NULL)")

  )

{

echo("created transaction table";

}

else

{

echo "-tran nt created-  " .mysql_error();

}

when i include this block of code no output is given  ???

Link to comment
Share on other sites

problem solved!!! ;D

the solution was

if (mysql_query("CREATE TABLE transaction

    (id INT(4) AUTO_INCREMENT NOT NULL PRIMARY KEY,

      source INT(7) UNSIGNED,

                              destination  INT(7) UNSIGNED,

                              amount INT(3) NOT NULL,

                              date DATE ,

      strt_time TIME ,

                              end_time  TIME ,

                              status ENUM(\"TRUE\",\"FALSE\") NOT NULL)")

  )

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.