ebolt007 Posted April 23, 2012 Share Posted April 23, 2012 Ok, so I have a REALLY strange problem. So I am trying to delete an array of checkboxes with an input delete piece and I have used a bit of a tutorial on the deletion part. But, my form works fine in IE9 when I do this and doesn't work in firefox when I have it inside a <form> tag. <form name="deletecheckbox" method="post" action=""> <input name="delete" class="delete_button" type="submit" id="delete" value="Delete" /> //some checkboxes pulled in dynamically thru ajax inside a loop and I won't put the whole looping code just what the checkbox looks like <input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$ID\"> <? $contact_query = "SELECT ID FROM Contacts ORDER BY ID ASC"; $contact_query_result = mysql_query($contact_query); $count=mysql_num_rows($contact_query_result); if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM Contacts WHERE ID='$del_id'"; $result = mysql_query($sql); } } ?> </form> Now, if I do the same thing without the form part, it works in Firefox but not in IE <input name="delete" class="delete_button" type="submit" id="delete" value="Delete" /> //some checkboxes pulled in dynamically thru ajax inside a loop and I won't put the whole looping code just what the checkbox looks like <input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$ID\"> <? $contact_query = "SELECT ID FROM Contacts ORDER BY ID ASC"; $contact_query_result = mysql_query($contact_query); $count=mysql_num_rows($contact_query_result); if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM Contacts WHERE ID='$del_id'"; $result = mysql_query($sql); } } ?> Anyone know what's goin on here? I'm lost. Quote Link to comment Share on other sites More sharing options...
nafetski Posted April 23, 2012 Share Posted April 23, 2012 Well, one thing I learned early on is if something is working in some browsers (and not others) the issue is never your PHP code. You can drive yourself THINKING that it is, but it's not...the issue you're having is how the browsers are handling malformed HTML, and that's solved easiest by validating your html! At first glace, the thing that sticks out is <input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$ID\"> If that is how they are being sent to the browser, it's going to choke . I would do it like this <?php foreach ($data as $row): ?> <input name="checkbox[]" type="checkbox" value="<?= $row['ID'] ?>"> <?php endforeach; ?> Make sure you don't have escaped quotes \" being sent to the browser, and ID's with html have to be UNIQUE. id="checkbox[]" means nothing to the browser, it's just going to start choking Quote Link to comment Share on other sites More sharing options...
chrisguk Posted April 23, 2012 Share Posted April 23, 2012 I not a fan of short tags either: <? somephp; ?> should be <?php somephp; ?> Quote Link to comment Share on other sites More sharing options...
nafetski Posted April 23, 2012 Share Posted April 23, 2012 It's weird, I hate php short tags by themselves - but I love using them in views and such. <?= $var ?> seems a lot prettier to me than <?php echo $var ?> (while in the context of a view) What drives me most insane tho, is when people echo out long strings of html inside php. Seems to be the most error prone way of doing things! Quote Link to comment Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 nafetski - Keep in mind short tags can be disabled. If you want your code to work on as many machines as possible, never use short tags. Quote Link to comment Share on other sites More sharing options...
nafetski Posted April 23, 2012 Share Posted April 23, 2012 Just because they can be disabled doesn't mean that they're not useful! If I'm writing an open source PHP library, you bet your ass I don't use short tags (tho it's pretty likely in that case I'm not escaping HTML either) Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 23, 2012 Share Posted April 23, 2012 It's weird, I hate php short tags by themselves - but I love using them in views and such. <?= $var ?> seems a lot prettier to me than <?php echo $var ?> (while in the context of a view) I agree, and I wish it was possible to do <?php= $var ?> Then we could all be happy. It's still shorter but won't cause the same problems as short tags. Quote Link to comment 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.