0

这是代码,我选择数据库以允许用户使用所有主题名称创建他们的数据库作为已创建数据库中的表。我在另一个数据库中创建新数据库表单时遇到问题。为此,我必须取消选择第一个选定的数据库。有人可以帮助我吗?提前致谢。

    <?php

    session_start();

    $con=mysql_connect("localhost","root","");

    $dept=$_SESSION['dept'];

    mysql_select_db("$dept",$con);

// getting all data from create html page

    $year=$_POST["adyear"];

    $table=$_POST["year"];

    $sem=$_POST["sem"];

    $databasename=$_POST["tablename"];

    $table1=$_POST["sub1name"];

    $table2=$_POST["sub2name"];

    $table3=$_POST["sub3name"];

    $table4=$_POST["sub4name"];

    $table5=$_POST["sub5name"];

    $table6=$_POST["sub6name"];

    if($year==""||$table1==""||$table2==""||$table3==""||$table4==""||$table5==""||$table6=="")

{


    echo"<script language=javascript>alert('oops..! you cannot leave subject field empty')</script>";


    echo"<META http-equiv='refresh'; content='0; URL=create.php'>";

}

    else

    {


    $sql="create database $dabasename";
        $s=mysql_query($sql);
        if($s)
        {


        $sql="insert into $table(".$year.",".$sem.",".$databasename.")";
            mysql_close();
            $con=mysql_connect("localhost","root","");
            mysql_select_db("$databasename",$con);
`       $sql="create table $table1(REGNO int, NAME varchar(50),Ist_Internal `int,II_Internal int,AVG int,ATTENACE int,FINAL_MARK int)";``

            mysql_query($sql);

            $sql="create table $table2(REGNO int, NAME varchar(50),Ist_Internal int,II_Internal int,AVG int,ATTENACE int,FINAL_MARK int)";


            mysql_query($sql);

    `       $sql="create table $table3(REGNO int, NAME varchar(50),Ist_Internal `int,II_Internal int,AVG int,ATTENACE int,FINAL_MARK int)";


            mysql_query($sql);



            $sql="create table $table4(REGNO int, NAME varchar(50),Ist_Internal int,II_Internal int,AVG int,ATTENACE int,FINAL_MARK int)";


            mysql_query($sql);

            $sql="create table $table5(REGNO int, NAME varchar(50),Ist_Internal int,II_Internal int,AVG int,ATTENACE int,FINAL_MARK int)";


            mysql_query($sql);

            $sql="create table $table6(REGNO int, NAME varchar(50),Ist_Internal int,II_Internal int,AVG int,ATTENACE int,FINAL_MARK int)";


            mysql_query($sql);

            echo"<script language=javascript>alert('table created now you can enter the student details')</script>";


            echo"<META http-equiv='refresh'; content='0; URL=menu.php'>";
        }


    else


    {


        echo"<script language=javascript>alert('oops...! table name already present. Give different tablename')</script>";




    echo"<META http-equiv='refresh'; content='0; URL=create.php'>";
        }

    }

    ?>
4

3 回答 3

0

您对应用程序架构的想法是错误的。

应该只有一个数据库和组表,都包含用户ID以区分特定用户的数据。

这是唯一的方法。

于 2013-03-17T14:18:46.183 回答
0

关闭第一个数据库-:

  mysql_close($con);
于 2013-03-17T14:12:47.530 回答
0

用于mysql_create_db创建新数据库,然后通过调用切换到它mysql_select_db

具体来说:

if(mysql_create_db($dabasename,$con))
{    
    mysql_select_db($dabasename,$con);
    $sql="insert into $table(".$year.",".$sem.",".$databasename.")";
于 2013-03-17T14:13:33.177 回答