It looks like you're new here. If you want to get involved, click one of these buttons!
<html>
<head>
<title>Extended Essay Submission</title>
</head>
<body>
<?php
if (isset($_POST['upload'])) {
if (!isset($_POST['user'])) {
exit('You must enter a username!');
}
if (!isset($_POST['password'])) {
exit('You must enter a password!');
}
if (!isset($_POST['type'])) {
exit('You must enter a submission type!');
}
if (!isset($_FILES['essay'])) {
exit('You must choose a file to upload!');
}
$_POST['user'] = addslashes(trim($_POST['user']));
$_POST['type'] = intval(trim($_POST['type']));
$_POST['password'] = md5($_POST['password']);
if (!strlen($_POST['user']) || $_POST['type'] < 1) {
exit('You must fill in every field on the form!');
}
if (!$link = mysql_connect('host', 'user', 'pass')) {
exit('Failed to connect to the database!');
}
if (!mysql_select_db('database', $link)) {
exit('Failed to select database!');
}
if (!$flink = fopen($_FILES['essay']['tmp_name'], 'rb')) {
exit('Failed to accept uploaded file!');
}
if (!$data = fread($flink, $_FILES['essay']['size'])) {
exit('Failed to read uploaded file!');
}
$data = addslashes($data);
$upload_sql = 'UPDATE essays SET essay="'.$data.'"';
$upload_sql .= ' WHERE username="'.$_POST['user'].'"';
$upload_sql .= ' AND password="'.$_POST['password'].'"';
if (!$upload_query = mysql_query($upload_sql, $link)
|| !mysql_affected_rows($link)) {
exit('File upload failed or already in database!');
}
echo '<h2>File upload success!</h2><hr />';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
Username: <input type="text" name="user" size="25" /><br />
Password: <input type="password" name="password" size="25" /><br /><br />
Submission type:
<select name="type" size="1">
<option value="1" selected="selected">Deadline 1</option>
<option value="2">Deadline 2</option>
<option value="3">Deadline 3</option>
<option value="4">Deadline 4</option>
<option value="5">Deadline 5</option>
</select>
<br /><br />
File: <input type="file" name="essay" /><br /><br />
<input type="submit" name="upload" value="Upload" />
</form>
</body>
</html>
Comments
from the code i see it already checks for duplicate files and stuff. sorry i cpouldnt do better