在PHP中创建具有多个动态字段的表

时间:2016-09-03 14:30:06

标签: javascript php mysql database create-table

只有我可以创建一个表行但我想创建多个表行我得到一个错误。 我认为查询中的错误但我不知道如何找到解决方案 如何添加多个表? 如何在查询单元中进行更改?

  <?php
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL ^ E_NOTICE);
    $con=mysql_connect("localhost","root","password");
    $table=mysql_select_db("databaseName") or die (mysql_error());
    if(isset($_POST['submit']))
    {
    $count2 = $_POST["hidden"];
     for($i=1;$i<=$count2;$i++)
     {
     $save = mysql_query("CREATE TABLE `".$_POST["dbName"]."`.`".$_POST["TableName"]."` ( `".$_POST["ColonName$i"]."` INT(".$_POST["LengthValues$i"].") NOT NULL COMMENT '".$_POST["Comments$i"]."' ) ENGINE = InnoDB");
     }
    if($save)
    { 
    echo '<script type="text/javascript">alert("Saved Success !");</script>';
    }
    else
    {
    echo '<script type="text/javascript">alert("Failed");</script>';
    }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>My Multiple Save </title>
    </head>

    <body>
    <center>
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="get"> <!-- Form for generate no of times -->
    <table align="center">
    <tr>
        <th colspan="3" align="center">Order Num Of Rows</th>
    </tr>
    <tr> 
        <td>VT ismi</td>
        <td><input type="text" name="dbName" /></td>
        <td>TabloAd</td>
        <td><input type="text" name="TableName" /></td>
        <td>No Of</td>
        <td><input type="text" name="no" /></td>
        <td><input type="submit" name="order" value="Generate" /></td>
    </tr>
    </table>
    </form><!-- End generate Form -->


    <!---- Create multiple Save Form,-->
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    <table align="center">
    <tr>
        <th colspan="3" align="left">Dynamic multiple Save To MySql</th>
    </tr>
    <tr>
        <td>tabloAdi</td>
        <td>VT</td>
        <td>Colon Name</td>
        <td>Leght</td>
        <td>Comment</td>
    </tr>
    <?php
    if(isset($_GET['order']))
    {
    $count = $_GET['no']-1; //get the num of times as numeric
    while($i <= $count)// loop by using while(),NOTE the looping dynamic textbox must be under the for loop othet must be outside                                                                                                                                                                                                                                                                                                                                                                                   of while()
    {
    $i++;
    ?>
    <tr>
        <td><input type="hidden" name="TableName" value="<?php echo $_GET["TableName"]; ?>"/></td>
        <td><input type="hidden" name="dbName" value="<?php echo $_GET["dbName"]; ?>"/></td>
        <td><input type="text" name="ColonName<?php echo $i; ?>" /></td>
        <td><input type="text" name="LengthValues<?php echo $i; ?>" /></td>
        <td><input type="text" name="Comments<?php echo $i; ?>" /></td>
    </tr>
    <?php
    }}
    ?>
    <tr>
        <td colspan="3" align="center">
        <input type="hidden" name="hidden" value="<?php echo $i; ?>" /><!-- Get max count of loop -->
        <input type="submit" name="submit" value="Save Multiple" /></td>
    </tr>
    </table>
    </form>
    </center>
    </body>
    </html>

0 个答案:

没有答案