View Single Post
  #6 (permalink)  
Old 10-24-09, 12:07 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
I changed your getAccessories() and updateItem() functions.
functions.php
PHP Code:

//----------Function for getting item accessories----------
function getAccessories()
{
 
$sql "SELECT accessories FROM tablename ORDER BY accessories";
 
$res mysql_query($sql);
 echo 
"<select name='accessories[]' size='4' multiple='multiple' class='input'><option value='-1'>------------------------</option>";
 while(
$row mysql_fetch_row($res))
 {
  if(!empty(
$_POST['accessories']))
  {
   if(
in_array($row[0],$_POST['accessories'])){echo  "<option value='".$row[0]."' selected>".$row[0]."</option>";}
   else{echo  
"<option value='".$row[0]."'>".$row[0]."</option>";}
   }
  else{echo  
"<option value='".$row[0]."'>".$row[0]."</option>";}
  }
 echo 
"</select>";
 }

//----------Function for updating item on mysql db----------
function updateItem($accessories,$id)
{
 
$sql "UPDATE theitem SET item_accessories = '" $accessories "' WHERE item_id = " $id "";
 
$res mysql_query($sql); // or die(mysql_error());
 

And I modified your update.php code.
PHP Code:

<?php
require_once ('library/database.php');
include (
'library/functions.php');
include (
'library/english.php');
$message "";
if(!empty(
$_POST['update_item']))
{
 if(empty(
$_POST['accessories']) || ($_POST['accessories'][0] == -&& empty($_POST['accessories'][1])))
 {
  
$message "EMPTY_FIELD";
  
$class "error";
  }
 else
 {
  if(
$_POST['accessories'][0] == -1){array_shift($_POST['accessories']);}
  
$_POST cleanCode($_POST);
  
$serializedaccessories serialize($_POST['accessories']);
  
updateItem($serializedaccessories,$_POST['item_id']);
  
$message "ITEM_EDITED";
  
$class "message";
  }
 }
?>
<HTML>
<HEAD></HEAD>
<BODY>
    <form action="#" method="post" name="fmpost">
     <input name="item_id" type="hidden" value="<?php echo $id//$id got from a function ?>" />
     <?php if($message){echo "<span class='$class'>$message</span>";} ?>    
     <div><label for="accessories" class="label">Accessories:</label><br /><span class="smallText">Hold down CTRL key and click to select multiple.</span></div>
     <div><?php getAccessories(); ?> </div>
     <div><input type="submit" name="update_item" value="Update" class="postbttn"/></div>
    </form>
</BODY>
</HTML>
__________________
Jerry Broughton

Last edited by job0107; 10-24-09 at 12:47 AM.
Reply With Quote