imarockstar Posted April 20, 2009 Share Posted April 20, 2009 hey i am trying to delete this row ... for some reason this does nt carry my $id over to the sql query ... here is the code .. deleteband is the value/name of the submit $id = $_POST['id']; $sid = $_POST['sid']; if ( $_POST['deleteband'] ) { $query = "DELETE FROM bands WHERE id = '$id' "; $result = mysql_query($query); header("Location: ../view_bands.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/ Share on other sites More sharing options...
The Little Guy Posted April 20, 2009 Share Posted April 20, 2009 make sure $id is the right value, you should echo it out. Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814915 Share on other sites More sharing options...
Maq Posted April 20, 2009 Share Posted April 20, 2009 How are you passing it? Why do you think it's not passing it? What happens? If delete_band is a button then use this instead: if (isset($_POST['deleteband'])) { Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814921 Share on other sites More sharing options...
laffin Posted April 20, 2009 Share Posted April 20, 2009 I agree with the little guy, have to find wut the vars are a cheap way of debugging is to add html comments but the header function wont work than, u can replace that with the meta tag for redirection. Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814925 Share on other sites More sharing options...
The Little Guy Posted April 20, 2009 Share Posted April 20, 2009 I would also change this: if ( $_POST['deleteband'] ) { to if ( isset($_POST['deleteband']) ) { This is assuming "deleteband" is a button Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814929 Share on other sites More sharing options...
Maq Posted April 20, 2009 Share Posted April 20, 2009 Is there an echo in here? Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814932 Share on other sites More sharing options...
imarockstar Posted April 20, 2009 Author Share Posted April 20, 2009 when i echo $id .. there is nothing .. Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814940 Share on other sites More sharing options...
imarockstar Posted April 20, 2009 Author Share Posted April 20, 2009 i will try if ( isset($_POST['deleteband']) ) { Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814941 Share on other sites More sharing options...
Maq Posted April 20, 2009 Share Posted April 20, 2009 when i echo $id .. there is nothing .. Can we see your form? Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814942 Share on other sites More sharing options...
imarockstar Posted April 20, 2009 Author Share Posted April 20, 2009 I echo the $id at the top of my delete script and it works ... but when I echo it after the IF statement .. it does not echo at all .. Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814948 Share on other sites More sharing options...
imarockstar Posted April 20, 2009 Author Share Posted April 20, 2009 here is the form .. <div id="deleteband" style="display:none"> Please choose a band to delete. <br> Remember !! This CAN NOT be undone !! <p><br> <form method='post' action='scripts/delete.php' enctype="multipart/form-data"> <select class="FMaddSHOW" name="id"> <option selected="selected">What Band ?</option> <? // Get records from database (table "name_list"). $list=mysql_query("select * from bands where userid = ". $_SESSION['id']); // Show records by while loop. while($row_list=mysql_fetch_assoc($list)){ ?> <option value="<? echo $row_list['id']; ?>"><? echo $row_list['b_name']; ?></option> <? // End while loop. } ?> </select> <p> Are you sure you want to delete this band ? <br> Are you 100% totally and surely for the most part sure ? <p><br> <input type="hidden" name="deleteband" value="Delete Band"> <input type="image" src="images/b_delete_band_small.png" name="deleteband" value="Delete Band"> <br> </form> </div> Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814951 Share on other sites More sharing options...
Maq Posted April 20, 2009 Share Posted April 20, 2009 Always use <?php tags, never short-hand as you use in your code, it minimizes portability. You need a name for this option. How is delete.php supposed to know what it is? What Band ? Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814954 Share on other sites More sharing options...
imarockstar Posted April 20, 2009 Author Share Posted April 20, 2009 The name is in the select : <select class="FMaddSHOW" name="id"> So the value of each option is what I am looking to retrieve ... here is the code to my whole delete script .. <?php include('settings.php'); $id = $_POST['id']; $sid = $_POST['sid']; $id = $_GET['id']; $delete = $_GET['delete']; if ( $_POST['deleteshow'] ) { $query = "DELETE FROM shows WHERE sid = ('$sid')"; $result = mysql_query($query); header("Location: ../view_shows.php"); } if ( isset($_POST['deleteband']) ) { $query = "DELETE FROM bands WHERE id = '$id' "; $result = mysql_query($query); header("Location: ../view_bands.php"); } if ( $_POST['deletetour'] ) { $query = "DELETE FROM tours WHERE id = ('$id')"; $result = mysql_query($query); header("Location: ../view_tours.php"); } if ( $_POST['deletetourdate'] ) { $query = "DELETE FROM tourdates WHERE id = ('$id')"; $result = mysql_query($query); header("Location: ../view_tours.php"); } if ( $_POST['deletecontact'] ) { $query = "DELETE FROM contacts WHERE id = ('$id')"; $result = mysql_query($query); header("Location: ../view_contacts.php"); } if ( $delete == 'deletefan') { $query = "DELETE FROM fans_email WHERE id = ('$id')"; $result = mysql_query($query); header("Location: ../view_fans.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814962 Share on other sites More sharing options...
soak Posted April 20, 2009 Share Posted April 20, 2009 I think the problem might be that you have two fields in your form called deleteband. If the browser uses the second one then because the field is of type image deleteband_x and deleteband_y will be set instead of deleteband. Change the name="" attribute of your image field. Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814965 Share on other sites More sharing options...
imarockstar Posted April 20, 2009 Author Share Posted April 20, 2009 are you talking about the HIDDEN tag named "deleteband" and then the IMAGE submit "deleteband" ? This is because IE does not accept images as submit buttons .. I have it this way on all my other forms and it seams to work ... if you look at the code from my above post, its the full DELETE script, which has multiple delete queries .. When I put an echo "$id" at the top after the $_POST and $_GETS its post the $id just fine ... Its when I place the $id inside the mysql query it will not work .. it wont even work anywhere inside the if statement ... Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814970 Share on other sites More sharing options...
soak Posted April 20, 2009 Share Posted April 20, 2009 Which suggests that $_POST['deleteband'] is not being set. Try it, it might work, it might not but you've got nothing to lose either way. Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814984 Share on other sites More sharing options...
imarockstar Posted April 20, 2009 Author Share Posted April 20, 2009 dude i totally miss-understood you .. and I am such a moron for not seeing that .. yeppers that was it .. thanks man Quote Link to comment https://forums.phpfreaks.com/topic/154929-solved-help-with-sql-delete/#findComment-814989 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.