Benim db 3 tablolar (aktörler, kategoriler, actor_cats) var.
I'm using a form to insert new info in the database (mysql). Most of the information goes into the actors table. But in a label "categories", i have a checkbox input type, with 3 fields that i get from the categories table [action (id1), comedy(id2), drama(id3)]. I want to insert this information in my actor_cats table. What i want to do is create a new actor in actors table, and also insert the checkbox selection (might be all 3 options) in the actors_cats table. This table as the actors id and the categories id, so what i want would be something like this:
Tablo actor_cats
satır 1 | actorid (1) | categoriesid (1)
satır 2 | actorid (1) | categoriesid (2)
Bir örnek olarak ...
nasıl ben mysqli kullanarak bu elde edebilirsiniz?
şimdiden teşekkürler!
Ben hala actor_cats tabloya yazamıyor. Bu ben ne yapıyorum:
/ / Yeni aktör taktıktan sonra
$jid = $mysql->insert_id;
if (isset($_POST['cats'])) {
$cats = $_POST['cats'];
} else {
$cats = array();
}
$numCats = 0;
foreach ($cats as $catID) {
$cats_sql = "INSERT INTO actor_cats VALUES(?,?)";
$stmt = $mysql->stmt_init();
if ($stmt->prepare($cats_sql)) {
$stmt->bind_param('ii', $jid, $catID);
$stmt->execute();
if ($ok) {
$numCats = $numCats + 1;
} else {
echo "<p>Error inserting $catID: " .
$mysql->error . '</p>';
}
}
<?php
else:
$cats = 'SELECT id, type FROM categories';
$stmt = $mysql->prepare($cats);
$stmt->execute();
$stmt->bind_result($catid,$cattype);
>
Ve onay kutusunu alanda benim şeklinde, benim kategoriler tablosunu alıp değerleri almak, bu yüzden formu göndermek, benim seçim sokulabilecektir
//excerpt from form
<label>Category:</label><br />
<?php while($row = $stmt->fetch()) : ?>
<input type="checkbox" name="cats" value="<?php echo $catid; ?>" /><?php echo $cattype; ?>
<br /><br /> <?php endwhile; ?>
Hope this is clear! Thanks all the guys for all the help!