grahamb314 Posted September 14, 2008 Share Posted September 14, 2008 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!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/ Share on other sites More sharing options...
grahamb314 Posted September 14, 2008 Author Share Posted September 14, 2008 Can someone explain why I have done `Show`.`Show in the PHP code? I cant remember and I reckon this could be part of the problem. Quote Link to comment https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/#findComment-641505 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/#findComment-641507 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 You only need to put in the field, not the database. Show.Show is the datase.table delete the first show so it is Also deleted the first ; it is not needed. "DELETE FROM `schedule` WHERE `Show`.`Show` ='{$_POST["toDelete"]}'"; Quote Link to comment https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/#findComment-641509 Share on other sites More sharing options...
gingerboy101 Posted September 14, 2008 Share Posted September 14, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/#findComment-641511 Share on other sites More sharing options...
grahamb314 Posted September 14, 2008 Author Share Posted September 14, 2008 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!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/#findComment-641513 Share on other sites More sharing options...
grahamb314 Posted September 14, 2008 Author Share Posted September 14, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/#findComment-641514 Share on other sites More sharing options...
grahamb314 Posted September 14, 2008 Author Share Posted September 14, 2008 If someone could post the code corrected with a little explination, that would be ace - (i think its only something small i have done wrong) I need to finish this soon and its really getting to me! Quote Link to comment https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/#findComment-641515 Share on other sites More sharing options...
grahamb314 Posted September 14, 2008 Author Share Posted September 14, 2008 To Help: There is the DB Table called schedule fields: ID Show StartTime EndTime Day Type Page Profile_url I changed the table a while ago, could that be the problem?? Quote Link to comment https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/#findComment-641518 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/#findComment-641570 Share on other sites More sharing options...
grahamb314 Posted September 15, 2008 Author Share Posted September 15, 2008 Perfect! Thank you everyone! Quote Link to comment https://forums.phpfreaks.com/topic/124228-solved-php-and-sql-delete-query/#findComment-642025 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.