我有简单的形式:与MySQL数据库的数据记录PHP问题
<form action="add.php" method="post" >
<input name="name" maxlength="30"/><br/>
<textarea cols="80" name="description" rows="10">
</textarea><br/>
<table>
<thead>
<tr>
<th></th>
<th width="200px">Shop list</th>
</tr>
</thead>
<tbody div class ="table">
<?php
$result = mysql_query("SELECT shop_id, name FROM shop") or die(mysql_error());
if(mysql_num_rows($result) > 0) {
while($row = mysql_fetch_assoc($result)) {
echo '<tr>
<td>
<input type="checkbox" name="identifer[]" value="'.$row['shop_id'].'" /> <br /></td>
<td>'.ucfirst($row['shop']).'</td>
</tr> ';
}
}
?>
</tbody></table>
<input type="submit" value="Add">
</form>
我要保存在数据库中的结果在两个不同的表:书(book_id,名称,描述)和地方 。在的地方表我想保存你可以购买那本书的商店(places_id,book_id,shop_id)。
我有add.php文件(它不工作):
<?php
$name = $_POST['name'];
$description = $_POST['description'];
$identifer =($_POST['identifer']);
if (isset($identifer)){
$id_arr = implode(',', $identifer);
$result = mysql_query("INSERT INTO places (places_id, book_id, shop_id) VALUES (NULL, NULL ($id_arr))") or die(mysql_error());
}
$q = "INSERT INTO baldas (book_id, name, description) VALUES (NULL, '$name', '$description')";
$result2 = mysql_query($q) or die(mysql_query());
?>
我很困惑我怎么也得保存两个不同的表结果的同时,我也有问题,鉴定复选框被检查并将结果写入数据库,特别是我不知道如何处理book_id。 任何建议都会有所帮助。
感谢您的快速响应。但我仍然可以做对。 :( 'foreach((array)$ _ POST ['identifier'] as $ shopID){ $ q2 =“INSERT INTO places(place_id,book_id,shop_id)VALUES(NULL,'$ bookID','$ shopID')“; \t $结果2 =请求mysql_query($ Q2)或死亡(的mysql_query());} ' 该代码给出了0的结果我错过了什么 – Lina
您的模具陈述必须是'mysql_error'。?。也许这会给你带来你遇到的错误(因为从我们迄今为止的信息来看INSERT看起来不错) – DTest