0

我有这个脚本,但是 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
}
?>
4

0 回答 0