簡體   English   中英

將數據插入表中

[英]Inserting data into the table

我有三個表:演員,電影和角色。 表角色解決了多對多關系的問題。 現在,我正在制作一個頁面以將移動添加到數據庫並分配一個參與者。

該表單將影片添加到表影片中,但不將記錄添加到表角色中。 這是我的代碼:

<form action="" method="post">
<table class="addactor">
<tr>
<td class="right">Movie code:</td> <td><input type="text" class="textfield" name="moviecode" value="" required></td>
</tr>
<tr>
<td class="right">Title:</td><td><input type="text" class="textfield" name="title" value="" required></td>
</tr>
<tr>
<td class="right">Date:</td><td><input type="text" class="textfield" name="dateofissue" value="" required></td>
</tr>
<tr>
<td class="right">Description:</td><td><input type="text" class="textfield" name="desc" value="" required></td>
</tr>
<tr>
<td class="right">Link to the image:</td><td><input type="text" class="image" name="image1" value="" required></td>
</tr>


</table>
<?php
$sqlquery="SELECT artistId, firstname, lastname from $artists order by 2";
$result = mysqli_query($connect, $sqlquery);
if($result)
    {
        echo "<table class=\"addactor\">";
        echo "<tr>
    <td id=\"text\" colspan=\"2\"><h3>Assign an actor to the movie</h3></td>
    </tr>";
        while  ($sqlRow=mysqli_fetch_array($result, MYSQL_ASSOC)) 
            {


                echo "<tr>";
                echo "<td>";
                echo"<input type=\"checkbox\" name=\"".$sqlRow['artistId']."\" value=\"".$sqlRow['artistId']."\"/> ".$sqlRow['firstname']." ".$sqlRow['lastname']."</td><td><input type=\"text\" name=\"role\"></td>";
                echo "</tr>";



            }

        echo"<tr><td align=\"right\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Add\"></td><td><input type=\"reset\" name=\"reset\" id=\"reset\" value=\"Reset\"></td></tr></table>;";

    }
print '</table>';






if ($_POST)
    {
        foreach($_POST as $key=>$value)
            {
                $sqlqr="INSERT INTO $roll (artistId, movieCode, roleDescription) VALUES ('".$sqlRow['artistId']."', '".$_POST['moviecode']."', '".$_POST['role']."')";
            }
        $query = "INSERT INTO $movies(movieCode, title, dateOfIssue, description, image) VALUES ('".$_POST['moviecode']."', '".$_POST['title']."', '".$_POST['dateofissue']."', '".$_POST['desc']."', '".$_POST['image1']."')";


        if (!mysqli_query($connect,$query)||!mysqli_query($connect, $sqlqr))
            {
                die('Error: ' . mysqli_error($connect));
            }
        else
            {
                echo "<h4>1 record added</h4>";
            }



        print '</form>';
    }
    ?>  

如果您能解決這個問題,我將不勝感激!

將$ roll替換為角色,將$ movies替換為電影,然后嘗試以下操作

INSERT INTO roll (artistId, movieCode, roleDescription) VALUES ('".$sqlRow['artistId']."', '".$_POST['moviecode']."', '".$_POST['role']."')";
$query = "INSERT INTO movies(movieCode, title, dateOfIssue, description, image) VALUES ('".$_POST['moviecode']."', '".$_POST['title']."', '".$_POST['dateofissue']."', '".$_POST['desc']."', '".$_POST['image1']."')";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM