Hello,
I am a noob and am struggling to work this out. I would appreciate help but am happier to receive a complete code to get me on my way so that I can tweak as nesissary once I know how it works.
I have a SQL database and a Form. The form is feeding the data into the db without issue. I need to add a file upload to my form and I'm not sure how best to do this. I would like to be able to save the file to the local server under the folder "uploads" and echo the image out in another page. i.e. echo row_$image.. i would like for the uploader to rename the image, possibly with timestamp or with a concatenation of date & username so that they are always unique.
this is a snippet from my from code.
any help will be greatly appreciated.
<input name="entrydet" id="da" value="A" type="radio" required>
<input name="entrydet" id="db" value="B+" type="radio">
<input name="entrydet" id="db1" value="B" type="radio">
<input name="entrydet" id="db2" value="B-" type="radio">
<input name="entrydet" id="dc" value="C" type="radio">
<input name="entrydet" id="dd" value="D" type="radio">
<label for="da" data-value="A">A</label>
<label for="db" data-value="B+">B+</label>
<label for="db1" data-value="B">B</label>
<label for="db2" data-value="B-">B-</label>
<label for="dc" data-value="C">C</label>
<label for="dd" data-value="D">D</label>
</div></div></section>
<div class="form-group form-group-lg" style="max-width: 700px;">
<label>Comments / Notes</label>
<input type="text" autocomplete="off" class="form-control" id="input-q9" name="comment" placeholder="Use this space to record comments or notes">
</div>
<!-- Hidden Inputs -->
<input type="hidden" autocomplete="off" class="form-control" name="user" id="user" value="<?php echo $_SESSION['username'];?>" readonly>
<input TYPE="hidden" name="timestamp" id="datetime" required value="<?php echo $closed;?>">
<input TYPE="hidden" name="contract" class="form-control" value="LBHF">
<INPUT TYPE="hidden" name="lon" ID="long">
<INPUT TYPE="hidden" name="lat" ID="lat">
<INPUT TYPE="hidden" name="nogps" ID="nogps">
<?php
// Check If form submitted, insert form data into table.
if(isset($_POST['Submit'])) {
$timestamp = $_POST['timestamp'];
$depot = $_POST['depot'];
$user = $_POST['user'];
$type = $_POST['type'];
$status = $_POST['status'];
$location = $_POST['location'];
$litter = $_POST['entrylitter'];
$detritus = $_POST['entrydet'];
$comment = $_POST['comment'];
$lat = $_POST['lat'];
$lon = $_POST['lon'];
$nogps = $_POST['nogps'];
$issue = $_POST['issue'];
$contract = $_POST['contract'];
// include database connection file
include_once("config.php");
// Insert user data into table
$result = mysqli_query($mysqli, "INSERT INTO refuse (timestamp, depot, user, type, location, litter, detritus, status, comment, lat, lon, nogps, image, contract) VALUES('$timestamp', '$depot', '$user', '$type', '$location', '$litter', '$detritus', '$status','$comment', '$lat', '$lon', '$nogps', '$image', '$contract')");
// Show message when user added
//echo "Job added successfully. <a href=page2.php'>View job list</a>";
header('Location: page2.php');
}
?>