Min kode ser sådan her ud, jeg kan få trukket mine kategorier ud via. min select, men ved ikke helt hvordan jeg gemmer categoryID i min fk_category_id
<?php
$allowedFileTypes = array('jpg','gif','png');
$uploadDir = '../photos/';
//Er der trykket på Upload file knappen?
if(isset($_POST['Submit'])){
//Har vi en fil?
if(is_uploaded_file($_FILES['photo']['tmp_name'])){
//Filendelse
$extension = strtolower(pathinfo($_FILES['photo']['name'],PATHINFO_EXTENSION));
//Er filen en af de filer vi gerne vil have?
if(in_array($extension,$allowedFileTypes)){
if( file_exists("../photos/" . $_FILES['photo']['name'])){
$file_name = substr( md5( time() ), 0, 10 ) . '_' . $_FILES['photo']['name'];
}else{
$file_name = basename($_FILES['photo']['name']);
}
//Vi flytter filen fra tmp til vores UPLOADDIR
if(move_uploaded_file($_FILES['photo']['tmp_name'],$uploadDir . $file_name))
{
$description = mysql_real_escape_string($_POST['description']);
mysql_query("INSERT INTO photos (description, photo) VALUES ('".$description."', '".$file_name."')")or die(mysql_error());
echo '<h3 style="color:green;">File ('.basename($_FILES['photo']['name']).') uploaded succesfully</h3>';
}else{
echo '<h3 style="color:red;">Error - unable to upload file: '.basename($_FILES['photo']['name']).'</h3>';
}
}else{
echo '<h3 style="color:red;">Wrong filetype, allowed filetypes are: ('.implode(',',$allowedFileTypes).')</h3>';
}
}else{
$description = mysql_real_escape_string($_POST['description']);
mysql_query("INSERT INTO photos (description, photo) VALUES ('".$description."', '".$file_name."')")or die(mysql_error());
echo '<h3 style="color:red;">No file selected</h3>';
}
}
?>
<form id="form1" name="form1" method="post" enctype="multipart/form-data" action="">
<table width="400" height="205" border="0" cellpadding="" cellspacing="1">
<tr>
<td><input type="file" name="photo"></td>
</tr>
<tr>
<td><textarea name="description" rows="8" cols="25" ></textarea></td>
</tr>
<tr>
<td><?php
$query = mysql_query("SELECT categoryID, name FROM categories") or die(mysql_error());
echo '<select name="category">\n';
echo '<option value="">vælg kategori</option>\n';
while($cats = mysql_fetch_assoc($query))
{
echo '<option value="'.$cats['categoryID'].'">'.$cats['name'].'</option>\n';
}
echo '</select>';
?></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Tilføj nyt" /></td>
</tr>
</table>
</form>