<?php
// Connect to server and select databse.
mysql_connect("localhost", "user", "password")or die("cannot connect");
mysql_select_db("database")or die("cannot select DB");
//Use SQL to get max value in ID column and use that to name the new file
$sql="SELECT max(id) FROM picture";
$result=mysql_query($sql);
$row = mysql_result($result,0,0);
//Max row is stored in $row
$idnum = $row;
$name = $_POST['name'];
$dat = date("M-N-Y");
$comments = $_POST['comments'];
$uploader = $_SESSION['name'];
$tag1 = $_POST['tag1'];
$tag2 = $_POST['tag2'];
$tag3 = $_POST['tag3'];
$tag4 = $_POST['tag4'];
$tag5 = $_POST['tag5'];
echo $idnum."<br />";
echo $name."<br />";
echo $dat."<br />";
echo $uploader."<br />";
echo $comments."<br />";
echo $tag1."<br />";
echo $tag2."<br />";
echo $tag3."<br />";
echo $tag4."<br />";
echo $tag5."<br />";
$sql2="INSERT INTO picture (`Filename`, `Upload Date`, `Uploader`, `Tag 1`, `Tag 2`, `Tag 3`, `Tag 4`, `Tag 5`, `ID`, `Comments`) VALUES ('$name`, `$dat`, `$uploader`, `$tag1`, `$tag2`, `$tag3`, `$tag4`, `$tag5`, `$idnum`, `$comments`)";
mysql_query($sql2);
$_FILES["file"]["name"] = $idnum;
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
//echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
move_uploaded_file($_FILES["file"]["tmp_name"],
"files/" . $_FILES["file"]["name"]);
echo "Stored in: " . "files/" . $_FILES["file"]["name"];
}
?>
All of the $_POST are set. What it's supposed to do is take an uploaded file, add a row in a MySQL table, and save the file. The file gets saved with the right name, but the info isn't put into the MySQL Table.
Sorry, I accidently left an extra end bracket ( } ) at the end. I removed it and the code still doesn't work. No errors reported and all of the variables have a value.
Question: Most of the tags (tag1, tag2, etc) are blank spaces; just a simple *. Is that what's causing the problem?
// Connect to server and select databse.
mysql_connect("localhost", "user", "password")or die("cannot connect");
mysql_select_db("database")or die("cannot select DB");
//Use SQL to get max value in ID column and use that to name the new file
$sql="SELECT max(id) FROM picture";
$result=mysql_query($sql);
$row = mysql_result($result,0,0);
//Max row is stored in $row
$idnum = $row;
$name = $_POST['name'];
$dat = date("M-N-Y");
$comments = $_POST['comments'];
$uploader = $_SESSION['name'];
$tag1 = $_POST['tag1'];
$tag2 = $_POST['tag2'];
$tag3 = $_POST['tag3'];
$tag4 = $_POST['tag4'];
$tag5 = $_POST['tag5'];
echo $idnum."<br />";
echo $name."<br />";
echo $dat."<br />";
echo $uploader."<br />";
echo $comments."<br />";
echo $tag1."<br />";
echo $tag2."<br />";
echo $tag3."<br />";
echo $tag4."<br />";
echo $tag5."<br />";
$sql2="INSERT INTO picture (`Filename`, `Upload Date`, `Uploader`, `Tag 1`, `Tag 2`, `Tag 3`, `Tag 4`, `Tag 5`, `ID`, `Comments`) VALUES ('$name`, `$dat`, `$uploader`, `$tag1`, `$tag2`, `$tag3`, `$tag4`, `$tag5`, `$idnum`, `$comments`)";
mysql_query($sql2);
$_FILES["file"]["name"] = $idnum;
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
//echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
move_uploaded_file($_FILES["file"]["tmp_name"],
"files/" . $_FILES["file"]["name"]);
echo "Stored in: " . "files/" . $_FILES["file"]["name"];
}
?>
All of the $_POST are set. What it's supposed to do is take an uploaded file, add a row in a MySQL table, and save the file. The file gets saved with the right name, but the info isn't put into the MySQL Table.
Sorry, I accidently left an extra end bracket ( } ) at the end. I removed it and the code still doesn't work. No errors reported and all of the variables have a value.
Question: Most of the tags (tag1, tag2, etc) are blank spaces; just a simple *. Is that what's causing the problem?