Forum Moderators: coopster

Message Too Old, No Replies

Help with MOD coppermine upload script

Arrays , PHP, Mysql, checkbox

         

noeinstein

9:55 am on Sep 16, 2008 (gmt 0)

10+ Year Member



Hi all, this is my first post in this forum and it will be a long one. I don't know much php and have been reading a lot of posts around the internet whitout finding any solution.

I have been banging my head against the wall for a week now trying to figure out what i am doing wrong when I am trying to customize upload.php for coppermine photo gallery.

What i am trying to do is to force users to select keywords from checkboxes instead of users writing their own keywords when they upload pictures.

<code>// Ok, go with "Easy keyword insert MOD v2"
//mod here

// The text Keyword form <---- modded input function. Takes the text label for the box, the input name, the maximum length for text boxes,
// and the number of iterations.
function keyword_box_input($text, $name, $max_length, $iterations, $default='') {

global $CONFIG;

$ordinal = '';

if (($text == '') and ($iterations == '')) {
echo " <input type=\"hidden\" name=\"$name\" value=\"$default\" />\n";
return;
}

// Begin loop
for ($counter=0; $counter<$iterations; $counter++) {

// Create a numbering system when necessary.
if ($text == '') {
$cardinal = $counter + 1;
$ordinal = "".$cardinal.". ";
}
// Hop stop here ! Add request of keyword_select.php to get the keyword list
$query = "SELECT * FROM {$CONFIG['TABLE_PREFIX']}dict ORDER BY keyword";
$result = cpg_db_query($query);

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$keywordIds[] = $row["keyId"];
$keywords[] = $row["keyword"];
}
$form = "";
foreach ($keywords as $keyword) {
$form.= '<input type="checkbox" name="keywords[]" value="'.$keyword.'">'.$keyword.'<br></input>';
}
// Return at the mod
// Create the keyword box.
echo <<< EOT
<tr>
<td width="40%" class="tableb" valign="top">
Kategorier :
</td>
<td width="60%" class="tableb" valign="top">
<div align="left">
<label>
$form
</label>
</div>

</td>
</tr>

EOT;
}
$keywords = addslashes(implode(',', $_POST['keywords']));

}
</code>

<code> // If the type is keyword input
case 5 :

// Call the text area function.
keyword_box_input($element[0], $element, $element[3], (isset($element[4])) ? $element[4] : '');
break;</code>

<code> // Declare an array containing the various upload form box definitions.
$captionLabel = $lang_upload_php['description'];
if ($CONFIG['show_bbcode_help']) {$captionLabel .= '&nbsp;'. cpg_display_help('f=index.html&amp;base=64&amp;h=' .urlencode(base64_encode(serialize($lang_bbcode_help_title))). '&amp;t='.urlencode(base64_encode(serialize($lang_bbcode_help))),470,245);}
$form_array = array(
sprintf($lang_upload_php['max_fsize'], $CONFIG['max_upl_size']),
array($lang_upload_php['album'], 'album', 2),
array('MAX_FILE_SIZE', $max_file_size, 4),
array($lang_upload_php['picture'], 'userpicture', 1, 1),
array($lang_upload_php['pic_title'], 'title', 0, 255, 1),
array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length']),
array($lang_upload_php['keywords'], 'keywords', 5, 255, 1),
array('event', 'picture', 4)
);</code>

<code> // We have incoming placement data. Let's capture it.

$album = (int)$_POST['album'];
$title = addslashes($_POST['title']);
$caption = addslashes($_POST['caption']);
$keywords = array_map('addslashes', $_POST['keywords']);
$user1 = addslashes($_POST['user1']);
$user2 = addslashes($_POST['user2']);
$user3 = addslashes($_POST['user3']);
$user4 = addslashes($_POST['user4']);</code>

<code> // Create thumbnail and intermediate image and add the image into the DB
$result = add_picture($album, $filepath, $picture_name, 0,$title, $caption, $keywords, $user1, $user2, $user3, $user4, $category, $raw_ip, $hdr_ip, $movie_wd, $movie_ht);</code>

<code> $form_array = array(
array($lang_upload_php['album'], 'album', 2),
array($lang_upload_php['pic_title'], 'title', 0, 255, 1, $title),
array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length'], (isset($iptc['Caption'])) ? $iptc['Caption'] : ''),
array($lang_upload_php['keywords'], 'keywords', 5, 255, 1,(isset($iptc['Keywords'])) ? implode(' ',$iptc['Keywords']): ''),
array('control', 'phase_2', 4),
array('unique_ID', $_POST['unique_ID'], 4),
);</code>

There are 2 problems with this:
1.The first checkbox get checked/unchecked when i change one of the others.
2. The only thing that is saved to the Database is 'Array'

I hope that someone will take a look an tell me what i am doing wrong.

Regards Noeinstein

[1][edited by: eelixduppy at 12:11 pm (utc) on Sep. 16, 2008]
[edit reason] side scroll [/edit]

coopster

1:08 pm on Sep 22, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, noeinstein.

input type checkbox in PHP requires an array if you want to return multiple values/selections. You accomplish this by using brackets on the name attribute's value. More information here is on the PHP manual page regarding PHP and HTML [php.net].

Your second issue is that you are attempting to write the array object to your database. You actually need to extract the values from the array and then write them to the database table.