Jump to content

[SOLVED] PHP and SQL Delete Query


grahamb314

Recommended Posts

Hi,

 

I have a small problem:

 

I have a page which displays a list of shows through a drop down box (there are 3 fields which populate the dropdown box from a DB -See code)

 

There is a bit of SQL (See code) which is supposed to delete the selected line from the drop down box, but nothing deletes from the DB! - Any clues? - Its probably something silly!

 

Webpage

<html>
<head>
<title></title>
</head>
<body>

<p align="center"><strong><img src="Purple_Logo.jpg" width="300" height="113" /></strong>
<p align="center"><strong>Delete a Show 
  </strong>
  </div>
<form action="delete_show_results.php" method="POST">

  <div align="center">
    <p>
      <select name="toDelete">
       
<?php
require_once 'mysql_connect.php';  
$DJshows = mysqli_query($mysqli, "SELECT * FROM schedule");
while ($show = mysqli_fetch_assoc($DJshows)) {  
echo "<option value=\"{$show['show']}\">{$show['ID']}  {$show['Show']}  {$show['StartTime']}</option>";
}
?>
      </select>
    </p>
    <p>
      <input type="submit" value="Delete"></p>
      
  </div>
</form>

</form>
    

<div align="center">
  <input name="BUTTON3" type="BUTTON" onClick="javascript:history.go(-1)" value="Back">
</div>
</body>
</html>

 

PHP

<?php 
require_once 'mysql_connect.php';
$query = "DELETE FROM `schedule` WHERE `Show`.`Show` ='{$_POST["toDelete"]}';";
mysqli_query($mysqli, $query) or die("Query:{$query} <br>Error:".mysqli_error($mysqli));
echo "<p>If there are no errors, the show <b> ".$_POST["toDelete"]." </b> has been deleted from the database!";
?>

 

Link to comment
Share on other sites

Sorry grahamb, Peranha, but should it not also read:

 

<?php
require_once 'mysql_connect.php';  
$DJshows = mysqli_query($mysqli, "SELECT * FROM schedule");
do {  
echo "<option value=\"{$show['show']}\">{$show['ID']}  {$show['Show']}  {$show['StartTime']}</option>";
}while ($show = mysqli_fetch_assoc($DJshows));
?>

 

Or am I just being silly?

Link to comment
Share on other sites

Okay I now have:

gingerboy101 - That doesnt work

 

(Still no errors and not deleting)

<?php 
require_once 'mysql_connect.php';
$query = "DELETE FROM `schedule` WHERE `Show` ='{$_POST["toDelete"]}'";
mysqli_query($mysqli, $query) or die("Query:{$query} <br>Error:".mysqli_error($mysqli));
echo "<p>If there are no errors, the show <b> ".$_POST["toDelete"]." </b> has been deleted from the database!";
?>

Link to comment
Share on other sites

Is the field show supposed to be Show, or show in the following line?

 

echo "<option value=\"{$show['show']}\">{$show['ID']} {$show['Show']} {$show['StartTime']}</option>";

 

 

Supposed to be Show - Like I say, I dont know what this does show.show, who not just show?

 

This should be

 

echo "<option value=\"{$show['Show']}\">{$show['ID']} {$show['Show']} {$show['StartTime']}</option>";

 

Show.Show is the database.table, this is not needed. you just need the field name.

 

Sorry grahamb, Peranha, but should it not also read:

 

<?php
require_once 'mysql_connect.php';  
$DJshows = mysqli_query($mysqli, "SELECT * FROM schedule");
do {  
echo "<option value=\"{$show['show']}\">{$show['ID']}  {$show['Show']}  {$show['StartTime']}</option>";
}while ($show = mysqli_fetch_assoc($DJshows));
?>

 

Or am I just being silly?

 

The drop down is displaying correctly, it is not getting the value due to the $show['show'] not being $show['Show'] as the database field is.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.