簡體   English   中英

從($ _GET [“ Value”])獲取值

[英]Getting the value from ($_GET[“Value”])

// PAGE ONE這是索引頁,在這里,我從電影列表中打印出一些基本信息(標題,年份)的行。 我還向電影添加了編輯和刪除鏈接,這些鏈接通過傳遞電影的行ID來實現。

 $sql = "SELECT c.* , d.* FROM category c , movies d WHERE c.ID=d.ID";

 $result = $conn->query($sql);

 if ($result->num_rows > 0) {
    echo "<div class='floatbox collection'><table><tr><th>Titel</th><th>regissör</th><th>År</th><th>Genre</th><th>Ändra</th><th>Ta bort</th>";

 while($row = $result->fetch_assoc()) {
    echo 
    "<tr><td>".$row["title"]."</td><td>".$row["director"]."</td><td>"

    .$row["year"]."</td><td>".$row["category"]."</td>

    <td><a href='edit.php?row=".$row["ID"]."'>justera</a></td>
        // delete link to send ID to next page
    <td><a href='delete.php?delete=".$row["ID"]."'>stryk</a></td>";
 }
 echo "</table></div>";
} else { 
    echo "0 results";
}



// PAGE TWO
Here I have my $row[ID] trough $_get by the link on the previous page,
I have checked the value by "dumping" so I know that the row ID is in that
variable: The thing is, How do I call that $ID in my sql statement?
I'm trying to delete by calling that ID on the table row.

// Variable with correct ID value
if(isset($_GET["ID"]))  

if($_GET["ID"]) = $ID; // This doesn't work, Do I need to convert 
the $get_ID to a variable with the ID that can be called in the statement? 
or is my syntax wrong?

// Delete join
$sql = "SELECT * FROM movies, category  
       INNER JOIN category ON movies.ID = category.ID
       DELETE WHERE movies.ID = '$ID'"; // No syntax works here
       // Any help appreciated.

// konfirmering
if ($conn->query($sql) === TRUE) {
    echo "Register struket <br>
     <a href='panel.php'>Gå tillbaka</a>";
} else {
    echo "Fel vid anslutning : " . $conn->error;
}

根據您的代碼,您的delete.php將如下所示:

// Variable with correct ID value
if (isset($_GET["delete"])) {
    $ID = $_GET["delete"];

    // Delete join
    $sql = "DELETE FROM movies, category INNER JOIN category ON movies.ID = category.ID WHERE movies.ID = '$ID'";

    // konfirmering
    if ($conn->query($sql) === TRUE) {
        echo "Register struket <br><a href='panel.php'>Gå tillbaka</a>";
    } else {
        echo "Fel vid anslutning : " . $conn->error;
    }
}

暫無
暫無

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

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