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
https://forums.phpfreaks.com/topic/40400-solved-multiple-tables-in-one-php-file/
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 ???

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  ???

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)")

  )

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.