SQL插入语句插入2条记录而不是1条记录

时间:2016-05-14 21:31:20

标签: php mysql

我见过有些人有同样的问题,但有不同的情况。而搜索只是给了'如何使用连接'。

当我通过我的php页面执行此操作时,会插入两条记录。一个是内容,一个是日期。我似乎无法找到日期字段的执行位置。我以前遇到过这个问题,但是对于mySQL的过去版本以及折旧值,所以使用新值对我来说更新。

下面是我的php和sql语句:

<?php
$link = mysqli_connect('server', 'username', 'password');
if (!$link) {
die('Could Not Connect: ' . mysqli_error());
}
else echo 'Connected Succesffully';
mysqli_select_db($link, 'database');

mysqli_query($link, "INSERT INTO tblcc 
                     (date , production , productionco , city , state , 
                      genre , type , details , part1 , gender1 , 
                      char1 , part2 , gender2 , char2 , part3 ,
                      gender3 , char3 , part4 , gender4 , char4 , part5 ,
                      gender5 , char5)
            VALUES(now() , '$_POST[production]' , '$_POST[productionco]' , '$_POST[city]' ,  '$_POST[state]' ,
                  '$_POST[genre]' , '$_POST[type]' , '$_POST[details]' , '$_POST[part1]' , '$_POST[gender1]' , 
                  '$_POST[char1]' , '$_POST[part2]' , '$_POST[gender2]' , '$_POST[char2]' , '$_POST[part3]' , 
                  '$_POST[gender3]' , '$_POST[char3]' , '$_POST[part4]' , '$_POST[gender4]' , '$_POST[char4]' ,
                  '$_POST[part5]' , '$_POST[gender5]', $_POST[char5]')");

mysqli_close($link);
?>

HTML:

<form action="http://enhstudios.com/bc1/submitcc.php/" method="post">
    <table border="3" cellpadding="3" cellspacing="3">
    <tr>
        <th>Production:</th>
        <th>Production Company:</th>
        <th colspan="2">Location:</th>
    </tr>
    <tr>
        <td><input type="text" name="production"></td>
        <td><input type="text" name="productionco"></td>
        <td><input type="text" name="city"></td>
        <td><select name="state">
            <option value=""></option>
            <option value="Illinois">Illinois</option>
            <option value="Indiana">Indiana</option>
            <option value="Iowa">Iowa</option>
            <option value="Kentucky">Kentucky</option>
            <option value="Missouri">Missouri</option>
            <option value="Ohio">Ohio</option>
            <option value="Wisconsin">Wisconsin</option>
            </select>
        </td>
    </tr>
    <tr>
        <th>Genre:</th>
        <th>Type:</th>
        <th colspan="2">Details:</th>
    </tr>
    <tr>
        <td><select name="genre">
            <option value=""></option>
            <option value="Action">Action</option>
            <option value="Comedy">Comedy</option>
            <option value="Drama">Drama</option>
            <option value="Horror">Horror</option>
            <option value="Romance">Romance</option>
            </select>
        </td>
        <td><select name="type">
            <option value=""></option>
            <option value="Feature Length">Feature Length</option>
            <option value="Mini-Series">Mini-Series</option>
            <option value="Short">Short</option>
            <option value="Web Series">Web Series</option>
            </select>
        </td>
        <td colspan="2"><textarea maxlength="255" rows="5" cols="30" name="details"></textarea></td>
    </tr>
    <tr>
        <th colspan="4">Parts:</th>
    </tr>
    <tr>
        <th>Role Type:</th>
        <th>Gender:</th>
        <th colspan="2">Character:</th>
    </tr>
    <tr>
        <td><select name="part1">
            <option value=""></option>
            <option value="Extra">Extra</option>
            <option value="Leading">Leading</option>
            <option value="Supporting">Supporting</option>
            </select>
        </td>
        <td><select name="gender1">
            <option value=""></option>
            <option value="Female">Female</option>
            <option value="Male">Male</option>
            </select>
        </td>
        <td colspan="2"><input type="text" name="char1">
        </td>
    </tr>
        <tr>
        <td><select name="part2">
            <option value=""></option>
            <option value="Extra">Extra</option>
            <option value="Leading">Leading</option>
            <option value="Supporting">Supporting</option>
            </select>
        </td>
        <td><select name="gender2">
            <option value=""></option>
            <option value="Female">Female</option>
            <option value="Male">Male</option>
            </select>
        </td>
        <td colspan="2"><input type="text" name="char2">
        </td>
    </tr>
        <tr>
        <td><select name="part3">
            <option value=""></option>
            <option value="Extra">Extra</option>
            <option value="Leading">Leading</option>
            <option value="Supporting">Supporting</option>
            </select>
        </td>
        <td><select name="gender3">
            <option value=""></option>
            <option value="Female">Female</option>
            <option value="Male">Male</option>
            </select>
        </td>
        <td colspan="2"><input type="text" name="char3">
        </td>
    </tr>
        <tr>
        <td><select name="part4">
            <option value=""></option>
            <option value="Extra">Extra</option>
            <option value="Leading">Leading</option>
            <option value="Supporting">Supporting</option>
            </select>
        </td>
        <td><select name="gender4">
            <option value=""></option>
            <option value="Female">Female</option>
            <option value="Male">Male</option>
            </select>
        </td>
        <td colspan="2"><input type="text" name="char4">
        </td>
    </tr>
        <tr>
        <td><select name="part5">
            <option value=""></option>
            <option value="Extra">Extra</option>
            <option value="Leading">Leading</option>
            <option value="Supporting">Supporting</option>
            </select>
        </td>
        <td><select name="gender5">
            <option value=""></option>
            <option value="Female">Female</option>
            <option value="Male">Male</option>
            </select>
        </td>
        <td colspan="2"><input type="text" name="char5">
        </td>
    </tr>
    <tr>
        <td><input type="submit" value="Submit"></td>
        <td colspan="3"></td>
    </tr>
    </table>
</form>

1 个答案:

答案 0 :(得分:-1)

我找到了&#34;问题&#34;。我将表单嵌入表中而不是表单中的表。