0

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" />

---- and the process page ---

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 Answers 2

2

Because your SELECT element is named "title," it will be represented as $_POST["title"] when it arrives to the backend script:

$title = $_POST['title'];

Also, your query needs to be corrected:

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

Should be:

$sql = "DELETE FROM tableName WHERE title = '{$title}'";
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, and how about the sql statement... how to gett that right??
0

$title is going to be in $_POST['title'] ie. $title = $_POST['title']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.