Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    updating multiple checkboxes? DELETE and INSERT INTO

    I am not getting any errors but it's not working?! Can someone please help??

    Edit checkboxes page
    Code:
    //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:
    Code:
    <?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);
    ?>

  • #2
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    can someone please help?

  • #3
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    if you're not seeing any errors it's probably in the sql somewhere.

    have you tried running it in phpmyadmin or anything?

  • #4
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    nope?!

    i think it's a problem with the foreach

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Where's $keyword_id being set? (on the code page)
    Last edited by Nightfire; 07-16-2008 at 04:35 PM.

  • #6
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    I sorted this now thanks to everyone that helped,
    I changed SELECT DISTINCT to SELECT * and changed bits of my form


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •