...

View Full Version : updating multiple checkboxes? DELETE and INSERT INTO



jarv
07-15-2008, 02:53 PM
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);
?>

jarv
07-16-2008, 09:04 AM
can someone please help?

ohgod
07-16-2008, 03:01 PM
if you're not seeing any errors it's probably in the sql somewhere.

have you tried running it in phpmyadmin or anything?

jarv
07-16-2008, 03:37 PM
nope?!

i think it's a problem with the foreach

Nightfire
07-16-2008, 04:32 PM
Where's $keyword_id being set? (on the code page)

jarv
07-17-2008, 08:37 AM
I sorted this now thanks to everyone that helped,
I changed SELECT DISTINCT to SELECT * and changed bits of my form



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum