Mysql den elemanı sil

2 Cevap php

using a drop-down list that's populated from database fields, i need to select an option and then delete that from the database. i'm trying to do this by sending the form to a process php page where i pull in the select option from the post array and then delete it from the database and return to the index page. having issues with getting the array variable from the post array. can anyone help with some code on how to get the variable and then delete the mysql title

<form method="post" action="deleteReview_process.php">

<select name="title">

    <?php
        while($row = mysql_fetch_array($sql_result)) {
            $movieTitle = $row['title'];
    ?>

<option><?php echo $movieTitle; ?></option>

    <?php } ?>

</select>

<input type="submit" name="delete" id="delete" value="delete" />

---- Ve süreç sayfa ---

include 'inc/db.inc.php';

if($_POST['delete']) {

    $title = $_POST['title'][$movieTitle];   <------ NOT WORKING


    $sql = "DELETE" . $title . "FROM pageTitle";
    mysql_query($sql, $conn)
        or die("couldn't execute query");


    header("Location: http://localhost/cms/index.php");

    }
    else
    {

    header("Location: http://localhost/cms/deleteReview.php");

    }

2 Cevap

Lütfen SELECT eleman "başlığı," o kadar temsil edilecek adlandırılır, çünkü $_POST["title"] bu backend script geldiğinde:

$title = $_POST['title'];

Ayrıca, sorgu düzeltilmesi gerekir:

$sql = "DELETE" . $title . "FROM pageTitle";

Olmalıdır:

$sql = "DELETE FROM tableName WHERE title = '{$title}'";

$title $_POST['title'], yani içinde olacak. $title = $_POST['title']