php mysql insert命令didn'添加第一列

时间:2013-02-19 18:08:05

标签: php mysql sql-insert

我有这个脚本,但mysql插入部分我有一个问题,脚本没有在sql表中插入第一列“DNS”,但确实插入了第二个和第三个。我的错误是第一栏逃脱的原因。

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
    $all = implode(",",$_POST);
    $all = explode(",",$all);

    $insert = "INSERT INTO Cname VALUES (";    

    for ($x=0;$x<3;$x++)
    {
        $all[$x] = clean($all[$x]);
        if ($all[$x] == "" || strlen($all[$x]) > 300)
            die("<p>Incorect Data Entry, Please check again! Column - " . $x);

        $insert .= "'" . $all[$x] . "',";
    }
    $insert .= "'')";

    $res = mysql_query($insert) or die(mysql_error());
    if($res)
        die("<p>Succesfully Added! <a href='index.php'>Back To View Page</a></p>");

} else {
    ?>
    <title>Add CNAME.</title>
    </head>
    <body>
    <?php include("nav.php");?>

    <div class="red"><p><h5>All fields are required.</h5></p></div>
    <table id="box-table-a"> 
    <tbody>
        <form action="" method="POST">
        <tr>
            <td>DNS</td>
            <!-- allow only the word CNAME  -->    
            <td><input type="text" name="DNS" placeholder="enter a word 'CNAME" required pattern="CNAME" title="enter a word 'CNAME' on this field"></td> 
        </tr>
        <tr>
            <td>name</td>
            <td><input type="text" name="name" placeholder="host with Full Domain Name" required  pattern="^[a-zA-Z0-9\-]*$" title="host with full Domain Name"></td>
        </tr>
        <tr>
            <td>alias</td>                                                                   
            <td><input type="text" name="alias" placeholder="only 3-15 digit are  allowed" required pattern="^[a-zA-Z0-9-_\-]{3,15}*$" title="only 3-15 digit are allowed"></td> 
        </tr>
        <tr>
            <td><input type="submit" value="Add Cname"></td>
            <td><input type="reset"></td>
        </tr>
    </tbody>
    </table>
    <?php
}
?>

0 个答案:

没有答案