joesaddigh Posted August 25, 2009 Share Posted August 25, 2009 Hi I have a piece of code which loops through some course dates and deleting the data but it does not seem to work. If i echo the delete query and use it phpmyadmin it works?? Can anybody see anything wrong with what I am doing. The code is as follows: The delete functionality <?php //Writing to the database so needs admin privileges require "../connectadmin.php"; //Get the username echo $date = $_POST['Delete_CourseDates']; echo $title = $_POST['CourseTitle']; //Get the course dates $query = "SELECT * FROM course WHERE CourseTitle = '$title'"; //Use this query below $result = mysql_query($query, $conn) or die ("Unable to perform query of course"); //Loop through the data set so that all of the course dates for the coursetitle are deleted while($row= mysql_fetch_array($result)) { //Get the courseid echo $id = $row['CourseId']; //Delete admin details from admin table echo $queryadmin = "DELETE FROM CourseDates WHERE CourseStartDate = '$date' AND CourseID =". $id; //Perform the query $admindetails = mysql_query($queryadmin, $conn) or die("Unable to delete course dates"); } //Redirect user back to admin page form //header("Location: course.php"); mysql_close($conn); exit(); ?> An example of its query output is as follows.... 2010-06-14General English44 DELETE FROM CourseDates WHERE CourseStartDate = '2010-06-14' AND CourseID =44 DELETE FROM CourseDates WHERE CourseStartDate = '2010-06-14' AND CourseID =45 DELETE FROM CourseDates WHERE CourseStartDate = '2010-06-14' AND CourseID =53 DELETE FROM CourseDates WHERE CourseStartDate = '2010-06-14' AND CourseID =54 etc.... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/171834-solved-looping-through-a-data-set-deleting-from-a-db-problem/ Share on other sites More sharing options...
mikesta707 Posted August 25, 2009 Share Posted August 25, 2009 stick or die("NO :" . mysql_error()); at the end of your query and see if you get an error Quote Link to comment https://forums.phpfreaks.com/topic/171834-solved-looping-through-a-data-set-deleting-from-a-db-problem/#findComment-906063 Share on other sites More sharing options...
schilly Posted August 25, 2009 Share Posted August 25, 2009 stick or die("NO :" . mysql_error()); at the end of your query and see if you get an error just about to say the same thing. <?php $admindetails = mysql_query($queryadmin, $conn) or die("MYSQL ERROR: " . mysql_errno() . " - " . mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/171834-solved-looping-through-a-data-set-deleting-from-a-db-problem/#findComment-906064 Share on other sites More sharing options...
joesaddigh Posted August 25, 2009 Author Share Posted August 25, 2009 Oh dear!!! I am an idiot,I had my own table name wrong! hahaha it is supposed to be lowercase!! Sorry to waste your time and thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/171834-solved-looping-through-a-data-set-deleting-from-a-db-problem/#findComment-906072 Share on other sites More sharing options...
schilly Posted August 25, 2009 Share Posted August 25, 2009 hehe don't worry. it happens to all of us. Quote Link to comment https://forums.phpfreaks.com/topic/171834-solved-looping-through-a-data-set-deleting-from-a-db-problem/#findComment-906076 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.