I intend to upload documents (file_up), categorize them in 4 main
categories (k_cat), have additional sub-categories (lec_cat) just for
querying and getting sub-categorized output of the files when listed
with date (dato_inn) and the submitters details "uploaded_b y".
But my script will not work. Anyone clever out there seeing what's
wrong?
This is my upload form, the script at the bottom:
<form enctype="multip art/form-data" id="uploadform " action="added.p hp"
method="post" name="uploadfor m">
<table width="90%" border="0" cellspacing="2" cellpadding="0" ><tr><td
width = "150"><div align="right">
<label for="fil">Choos e file to upload: </label>
</div></td>
<td><input id="file_up" name="file_up" type="file" size="50" value=""
maxlength="255" ></td></tr><tr><td width = "150"><div align="right">
<label for="k_cat">Cho ose main category: </label>
</div></td>
<td><select name="k_cat" id="k_cat">
<option value="Category _1">Category_ 1</option>
<option value="Category _2">Category_ 2</option>
<option value="Category _3">Category_ 3</option>
<option value="Category _4">Category_ 4</option>
</select>
</td></tr><tr><td width = "150"><div align="right">
<label for="lev_cat">C hoose sub category </label>
</div></td>
<td><select name="lev_cat" id="lev_cat">
<option value="Category _1_Sub_1">Categ ory_1_Sub_1</option>
<option value="Category _1_Sub_2">Categ ory_1_Sub_2</option>
<option value="Category _1_Sub_3">Categ ory_1_Sub_3</option>
<option value="Category _1_Sub_4">Categ ory_1_Sub_4</option>
<option value="Category _2_Sub_1">Categ ory_2_Sub_1</option>
<option value="Category _2_Sub_2">Categ ory_2_Sub_2</option>
<option value="Category _2_Sub_3">Categ ory_2_Sub_3</option>
<option value="Category _2_Sub_4">Categ ory_3_Sub_4</option>
</select></td></tr><tr><td width = "150"><div align="right">
<label for="dato_inn"> Date uploaded</label>
</div></td>
<td><input id="dato_inn" name="dato_inn" type="text" size="25"
value="" maxlength="255" ></td></tr><tr><td width = "150"><div
align="right">
<label for="uploaded_b y">Uploaded by:</label>
</div></td>
<td><input id="uploaded_by " name="uploaded_ by" type="text" size="25"
value="" maxlength="255" ></td></tr><tr><td width="150"></td><td>
<input type="submit" name="submitBut tonName" value="Add file and entry
to DB"></td>
</tr></table>
</form>
<?php
//this is added.php
include("connec t.php");
$file_up = $_POST['file_up'];
$k_cat = $_POST['k_cat'];
$lev_cat = $_POST['lev_cat'];
$dato_inn = $_POST['dato_inn'];
$uploaded_by = $_POST['uploaded_by'];
if $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_1' {
move_uploaded_f ile ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_1/{$_FILES['file_up'] ['name']}")
}
elseif $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_2' {
move_uploaded_f ile ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_2/{$_FILES['file_up'] ['name']}")
}
elseif $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_3' {
move_uploaded_f ile ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_3/{$_FILES['file_up'] ['name']}")
}
elseif $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_4' {
move_uploaded_f ile ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_4/{$_FILES['file_up'] ['name']}")
}
$query = "INSERT INTO lev_database (id, file_up, k_cat, lev_cat,
dato_inn, uploaded_by)
VALUES ('', '$file_up', '$k_cat', '$lev_cat', '$dato_inn',
'$uploaded_by') ";
$results = mysql_query($qu ery) or die
("Could not execute query : $query." . mysql_error());
if ($results)
{
echo "Details added.";
}
mysql_close();
?>
categories (k_cat), have additional sub-categories (lec_cat) just for
querying and getting sub-categorized output of the files when listed
with date (dato_inn) and the submitters details "uploaded_b y".
But my script will not work. Anyone clever out there seeing what's
wrong?
This is my upload form, the script at the bottom:
<form enctype="multip art/form-data" id="uploadform " action="added.p hp"
method="post" name="uploadfor m">
<table width="90%" border="0" cellspacing="2" cellpadding="0" ><tr><td
width = "150"><div align="right">
<label for="fil">Choos e file to upload: </label>
</div></td>
<td><input id="file_up" name="file_up" type="file" size="50" value=""
maxlength="255" ></td></tr><tr><td width = "150"><div align="right">
<label for="k_cat">Cho ose main category: </label>
</div></td>
<td><select name="k_cat" id="k_cat">
<option value="Category _1">Category_ 1</option>
<option value="Category _2">Category_ 2</option>
<option value="Category _3">Category_ 3</option>
<option value="Category _4">Category_ 4</option>
</select>
</td></tr><tr><td width = "150"><div align="right">
<label for="lev_cat">C hoose sub category </label>
</div></td>
<td><select name="lev_cat" id="lev_cat">
<option value="Category _1_Sub_1">Categ ory_1_Sub_1</option>
<option value="Category _1_Sub_2">Categ ory_1_Sub_2</option>
<option value="Category _1_Sub_3">Categ ory_1_Sub_3</option>
<option value="Category _1_Sub_4">Categ ory_1_Sub_4</option>
<option value="Category _2_Sub_1">Categ ory_2_Sub_1</option>
<option value="Category _2_Sub_2">Categ ory_2_Sub_2</option>
<option value="Category _2_Sub_3">Categ ory_2_Sub_3</option>
<option value="Category _2_Sub_4">Categ ory_3_Sub_4</option>
</select></td></tr><tr><td width = "150"><div align="right">
<label for="dato_inn"> Date uploaded</label>
</div></td>
<td><input id="dato_inn" name="dato_inn" type="text" size="25"
value="" maxlength="255" ></td></tr><tr><td width = "150"><div
align="right">
<label for="uploaded_b y">Uploaded by:</label>
</div></td>
<td><input id="uploaded_by " name="uploaded_ by" type="text" size="25"
value="" maxlength="255" ></td></tr><tr><td width="150"></td><td>
<input type="submit" name="submitBut tonName" value="Add file and entry
to DB"></td>
</tr></table>
</form>
<?php
//this is added.php
include("connec t.php");
$file_up = $_POST['file_up'];
$k_cat = $_POST['k_cat'];
$lev_cat = $_POST['lev_cat'];
$dato_inn = $_POST['dato_inn'];
$uploaded_by = $_POST['uploaded_by'];
if $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_1' {
move_uploaded_f ile ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_1/{$_FILES['file_up'] ['name']}")
}
elseif $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_2' {
move_uploaded_f ile ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_2/{$_FILES['file_up'] ['name']}")
}
elseif $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_3' {
move_uploaded_f ile ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_3/{$_FILES['file_up'] ['name']}")
}
elseif $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_4' {
move_uploaded_f ile ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_4/{$_FILES['file_up'] ['name']}")
}
$query = "INSERT INTO lev_database (id, file_up, k_cat, lev_cat,
dato_inn, uploaded_by)
VALUES ('', '$file_up', '$k_cat', '$lev_cat', '$dato_inn',
'$uploaded_by') ";
$results = mysql_query($qu ery) or die
("Could not execute query : $query." . mysql_error());
if ($results)
{
echo "Details added.";
}
mysql_close();
?>
Comment