jarv Posted July 15, 2008 Share Posted July 15, 2008 I am not getting any errors but it's not working?! Can someone please help?? Edit checkboxes page //SQL for Keywords $result2 = mysql_query("SELECT DISTINCT keyword from keywordlist"); $i = 0; while ($row1 = mysql_fetch_array($result2)) { if ($i++ > 0) { echo '<br> '; } $Keyword = $row1['keyword']; $Displayed = false; //SQL for Keywords $result3 = mysql_query("SELECT * FROM keyword INNER JOIN keywordlist ON keyword.keyword_id=keywordlist.keyword_id WHERE keyword.HeaderID=".$HeaderID); while($row3 = mysql_fetch_array($result3)) { $Keyworduse = $row3['keyword']; $keyword_id = $row3['keyword_id']; if ($Keyworduse == $Keyword) { $Displayed = true; $check = ' checked="checked"'; echo '<input name="keyword_id[]" type="checkbox" value="'.$keyword_id.'" '.$check.' />'; echo $Keyword; } } if ($Displayed == false) { echo '<input name="keyword_id[]" type="checkbox" value="'.$Keyword.'"/>'; echo $Keyword; } } code page: <?php include_once('config.php'); $HeaderID = $_GET['HeaderID']; $sql = "DELETE FROM keyword WHERE HeaderID = '$HeaderID'"; $result = mysql_query($sql,$link) or die('Error: ' . mysql_error() . '<br>SQL: ' . $sql); if (is_array($_POST['keyword_id'])) { foreach ($_POST['keyword_id'] AS $keyword) { $keyword_id = mysql_real_escape_string(stripslashes($keyword)); $sql1 = "INSERT INTO keyword (keyword_id,HeaderID) Values ('$keyword_id','$HeaderID')"; $result = mysql_query($sql1,$link) or die('Error: ' . mysql_error() . '<br>SQL: ' . $sql1); } } header("Location: display.php"); mysql_close($link); ?> Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/ Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 What do you mean doesn't work ?! Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-590611 Share on other sites More sharing options...
jarv Posted July 15, 2008 Author Share Posted July 15, 2008 I think it deletes the records but then nothing gets INSERT INTO?! Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-590627 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 add some debugging ie $sql1 = "INSERT INTO keyword (keyword_id,HeaderID) Values ('$keyword_id','$HeaderID')"; echo $sql1; //debug code Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-590645 Share on other sites More sharing options...
jarv Posted July 15, 2008 Author Share Posted July 15, 2008 I put the debugging in and i got back: INSERT INTO keyword (keyword_id,HeaderID) Values ('HIV-positive','25')Error: Incorrect integer value: 'HIV-positive' for column 'keyword_id' at row 1 SQL: INSERT INTO keyword (keyword_id,HeaderID) Values ('HIV-positive','25') Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-591013 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 on the script that builds the form you have echo '<input name="keyword_id[]" type="checkbox" value="'.$Keyword.'"/>'; can you comment out that line and test.. Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-591021 Share on other sites More sharing options...
jarv Posted July 16, 2008 Author Share Posted July 16, 2008 if i comment out that line, I lose all my empty checkboxes?! Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-591344 Share on other sites More sharing options...
MadTechie Posted July 16, 2008 Share Posted July 16, 2008 its a test.. dose it work without error.. (i'll assume so) now change echo '<input name="keyword_id[]" type="checkbox" value="'.$Keyword.'"/>'; to echo '<input name="keyword_id[]" type="checkbox" value="'.$keyword_id.'"/>'; Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-591484 Share on other sites More sharing options...
jarv Posted July 16, 2008 Author Share Posted July 16, 2008 yes, it checks the relevant checkboxes but when i try and edit them on a DELETE and INSERT INTO statement, it doesn't work?! Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-591488 Share on other sites More sharing options...
MadTechie Posted July 16, 2008 Share Posted July 16, 2008 opps edited the last post and here it is again now change echo '<input name="keyword_id[]" type="checkbox" value="'.$Keyword.'"/>'; to echo '<input name="keyword_id[]" type="checkbox" value="'.$keyword_id.'"/>'; Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-591491 Share on other sites More sharing options...
jarv Posted July 16, 2008 Author Share Posted July 16, 2008 I changed that and I got: Notice: Undefined variable: Keyword_id in /Users/staff/Sites/johns/headers/editkeywords.php on line 67 that was line 67 Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-591525 Share on other sites More sharing options...
MadTechie Posted July 16, 2008 Share Posted July 16, 2008 oops i didn't notice it was outside the loop try echo '<input name="keyword_id[]" type="checkbox" value="'. $row1['keyword'].'"/>'; Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-591545 Share on other sites More sharing options...
jarv Posted July 16, 2008 Author Share Posted July 16, 2008 a 0 gets inserted into the keyword database for the keyword_id so yeah, it's not passing through the keyword_id from the posting page Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-591633 Share on other sites More sharing options...
jarv Posted July 16, 2008 Author Share Posted July 16, 2008 I've done it thanks! I had to change SELECT DISTINCT to SELECT * in $row1 Quote Link to comment https://forums.phpfreaks.com/topic/114851-update-multiple-checkboxes-delete-and-insert-into/#findComment-591643 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.