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
https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/
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?

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!";
?>

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.