-1
我見過一些人有同樣的問題,但情況不同。搜索只是給了我'如何使用連接'。SQL插入語句插入2條記錄而不是1條
當我通過我的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>
你可以在這裏發表你的表格嗎?調用此頁的頁面 –
該PHP代碼不會創建2行。但是,如果你打電話給它兩次,可能會解釋它。但是因爲你不顯示你怎麼稱呼它,我們無法確定。如果你看看'event.preventDefault()'是否能解決你的問題,我猜你是從AJAX調用中調用這段代碼。 – RiggsFolly
我添加了一個鏈接到表單;我認爲看起來很好,至少與其他形式相比。我不理解的是它沒有在第二條記錄中發佈任何其他內容,僅僅是日期。我沒有收集任何日期數據,它是由服務器設置的。 –