I select the first catagory from the first dropdown which populates the second catagory selection list.
Then I browse for a file using the browse button which populates the file textbox with the location.
Then I fill out the description box and press submit.
Code: Select all
<?php
include 'config.php';
include 'opendb.php';
///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT category,cat_id FROM category order by category");
///////////// End of query for first list box////////////
/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT subcategory FROM subcategory where cat_id=$cat order by subcategory");
}else{$quer=mysql_query("SELECT DISTINCT subcategory FROM subcategory order by subcategory"); }
////////// end of query for second subcategory drop down list box ///////////////////////////
echo "<form method=post name=f1 action='dd-check.php'>";
/// Add your form processing page address to action in above line. Example action=dd-check.php////
////////// Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";}
else{echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";}
}
echo "</select>";
////////////////// This will end the first drop down list ///////////
////////// Starting of second drop downlist /////////
echo "<select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[subcategory]'>$noticia[subcategory]</option>";
}
echo "</select>";
////////////////// This will end the second drop down list ///////////
//// Add your other form fields as needed here/////
echo "<input type=submit value=Submit>";
echo "</form>";
/////////// Start of upload Documents code ////////////////////////////
// you can change this to any directory you want
// as long as php can write to it
$uploadDir = 'C:/websites/user_login/uploads/';
echo "Select your story <b>$session->username</b>, then click upload. <br>";
if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
// get the file extension first
$ext = substr(strrchr($fileName, "."), 1);
// generate the random file name
$randName = md5(rand() * time());
// and now we have the unique file name for the upload file
$filePath = $uploadDir . $randName . '.' . $ext;
// the files will be saved in filePath
// $filePath = $uploadDir . $fileName;
// move the files to the specified directory
// if the upload directory is not writable or
// something else went wrong $result will be false
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
echo "<br>File uploaded<br>";
/* Link back to main */
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br>";
}
///////////////////////////////// End of document upload ////////////////////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<link rel="stylesheet" type="text/css" href="/styles/yourfile.css">
<title>Upload File To MySQL Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile">
</td>
</tr>
</table>
</head>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dd.php?cat=' + val ;
}
</script>
<body>
Decription:<input type="text" name="description"><br>
<?
?>
<center><a href='http://www.plus2net.com'>PHP SQL HTML free tutorials and scripts</a></center>
</body>
</html>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>This information is passed to the DB using dd-check.php
Code: Select all
<?php
error_reporting(E_ALL);
include 'config.php';
include 'opendb.php';
$description=$_POST['description'];
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$query = "INSERT INTO upload2 (name, size, type, path, description, AuthorID, category, subcategory ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath', '$description', '$session->username', '$cat', '$subcat')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
echo $query;
include 'closedb.php';
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br>";
echo "<br>File uploaded<br>";
/* Link back to main */
?>Code: Select all
INSERT INTO upload2 (name, size, type, path, description, AuthorID, category, subcategory ) VALUES ('', '', '', '', '', '', '2', 'Blue')
Back To [Main]
File uploaded
PHP Notice: Undefined index: description in C:\websites\user_login\upload2\dd-check.php on line 8 PHP Notice: Undefined index: userfile in C:\websites\user_login\upload2\dd-check.php on line 9 PHP Notice: Undefined index: userfile in C:\websites\user_login\upload2\dd-check.php on line 10 PHP Notice: Undefined index: userfile in C:\websites\user_login\upload2\dd-check.php on line 11 PHP Notice: Undefined index: userfile in C:\websites\user_login\upload2\dd-check.php on line 12 PHP Notice: Undefined variable: filePath in C:\websites\user_login\upload2\dd-check.php on line 17 PHP Notice: Undefined variable: session in C:\websites\user_login\upload2\dd-check.php on line 17 PHP Notice: Trying to get property of non-object in C:\websites\user_login\upload2\dd-check.php on line 17Can anyone tell mw why, I'm a total novice at PHP as you can see.
Geoff