Vineet Basantani Vineet Basantani - 1 year ago 149
MySQL Question

Unable to delete entry from table where value contains a space in the middle?

I'm able to delete the entries which have a single word like 'Tomato' or 'Potato'.
Unable to delete entries with multiple words like 'pumpkin soup'.

Why is that?

Here's my PHP:

$sth = $conn->prepare("DELETE FROM event WHERE event_name=:del");
header( "Refresh: 0;" );

And this is how I'm loading the values in drop down:

<select name="event_name_box" value="event_name_box" style="width:220px; padding-left:40px;font-size:18px;font-family:Roboto;">
$sth = $conn->prepare('Select event_name From event');
$data = $sth->fetchAll();
foreach ($data as $row ){
echo " <option id=\"EventName\" name=\"EventName\" value=".$row['event_name'].">".$row['event_name']."</option>";
<input type="submit" name="submit" style="width:50%;padding:10px" value="Delete"</input>

Answer Source

The problem is in your HTML (specifically, the <option> tag). Your value isn't quoted, so the space is breaking the value sent in the POST. Change the echo on your option to something like this:

echo '<option value="' . $row['event_name'] . '">' . $row['event_name'] . '</option>';

(You also shouldn't need the name and id on your <option> tags.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download