Those checkboxes again

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi,
I'm severely frustrated and perhaps you can help with what I have done wrong. The checkboxes I use to populate an intersection table work to add the records, and now I am trying to update them. It's almost there but producing some unexpected results when the form is submitted: the idea is that it displays the checkboxes as pre-selected if they're associated with the art_id in the intersection table. They're now appearing as all unselected. Any help is appreciated.

<?php

$query = '';
$result = 0;
$art_id = $_POST['art_id'];

print_r($_POST);

if (isset($_POST['editrecordMedia'])){

	if (!empty($_POST['media_types'])) {

		foreach($_POST['media_types'] as $type)
		 {
			 $query = "UPDATE media_art SET
			 media_id='$type',
			 art_id='$art_id'";
var_dump($query);
			 mysql_query($query) or die(mysql_error());

		 }
	}
	
	else {echo "mediatypes is empty";}
	//Closes if (!empty($media_types))
    }//closes if (isset($_POST['editrecordMedia'])

//If editrecord hasn't been set, but selectcartoon has, get the cartoon's recordset
	
//This is just to get the title for display purposes
$query = "SELECT art_title
	FROM art
	WHERE art_id='$art_id'";
//end

	$media_query = "SELECT media.media_id,
		media.media_name,
		media_art.art_id
		FROM media
		LEFT JOIN media_art
		ON media_art.media_id=media.media_id
		AND media_art.art_id='$art_id'";

//These $art results are just to get the title for display purposes
$art_result = mysql_query($query);		
$art_rows = mysql_fetch_assoc($art_result);
//end

$media_result = mysql_query($media_query);
$checkbox_media = array ();


while ($media_rows = mysql_fetch_assoc($media_result)){
	
$checkbox_media[] = "<input type='checkbox' name='media_types[]' value='{$media_rows['media_id']}' ";
	
	if ($media_rows['art_id'] === $art_id) {
		$checkbox_media[] .= "checked ";
		}
		
		$checkbox_media[] .= "/>{$media_rows['media_name']}  ";

		
}

?>

<table align="center">
        <tr><th colspan="4">Main Menu</th></tr>
    <tr>
        <td><a href="addrecord.php">Add A Record</a></td>
        <td><a href="chooserecord.php">Edit A Record</a></td>
        <td><a href="deleterecord.php">Delete A Record</a></td>
    </tr>
</table>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="editrecordMedia">
<input type="hidden" name="art_id" value="<?php echo $art_id ;?>">
Choose media related to <strong><?php echo $art_rows['art_title'];?></strong><br /><br />

 Media: <?php echo join($checkbox_media); ?>

<input type="submit" name="editrecordMedia" value="Update">
    </form>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux