I have simple form:
<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>
I want to save the results in database in two different tables: book (book_id, name, description) and places. In places table I want to save shops where you can buy that book (places_id, book_id, shop_id).
I have add.php file (it’s not working):
<?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());
?>
I’m confused how I have to save results in two different tables in the same time, also I have problems with identifying which checkboxes are checked and to write the results in database, especially I have no idea how to deal with book_id.
Any advice would be helpful.
You would first insert the values into table
baldas, then callmysql_insert_id()The way you have them, you’d have to loop through the
$_POST['identifier']array to identify the shop_idIf it’s not checked it won’t show up in the
$_POST