Dear All,
I feel as though I am getting closer to my objective but the reality is that I am probably getting further away. I have created a custom form (code below), and added some php to the on submit before sending (again, code below). I also believe that I have the various form elements configured correctly i.e. email results-yes, form tag attachment-enctype... form method-post etc etc etc. When I test the form it appears to work correctly (see debug dump below) and all the 'posted' values are what I would expect. The problem is none of those values are getting saved to the database table, which leads me to the insert query - I just can't see the wood for the trees and having circumnavigated the planet at least 4 times I am now in despair.
TIA & Best Regards
Form Code
On Submit...
Debug...
[attachment=0]Screen shot 2010-12-10 at 10.10.38.png[/attachment]
I feel as though I am getting closer to my objective but the reality is that I am probably getting further away. I have created a custom form (code below), and added some php to the on submit before sending (again, code below). I also believe that I have the various form elements configured correctly i.e. email results-yes, form tag attachment-enctype... form method-post etc etc etc. When I test the form it appears to work correctly (see debug dump below) and all the 'posted' values are what I would expect. The problem is none of those values are getting saved to the database table, which leads me to the insert query - I just can't see the wood for the trees and having circumnavigated the planet at least 4 times I am now in despair.
TIA & Best Regards
Form Code
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th colspan="3" scope="col">Annaveigh Delivery Note Upload Area</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Customer Name</td>
<td>Reference ID</td>
<td>Delivery Date</td>
</tr>
<tr>
<td><input type="text" name="custname" id="custname" tabindex="10" /></td>
<td><input type="text" name="delrefno" id="delrefno" tabindex="20" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Delivery Note No.</td>
<td> </td>
<td>File Upload</td>
</tr>
<tr>
<td><input type="text" name="delnoteno" id="delnoteno" tabindex="40" /></td>
<td> </td>
<td><input type="file" name="uploaded_file" id="uploaded_file" tabindex="60" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="Upload File" tabindex="70" /></td>
<td><input type="reset" name="cancel" id="cancel" value="Cancel" /></td>
<td> </td>
</tr>
</table>
On Submit...
<?php
// Check if a file has been uploaded
if(isset($_FILES['uploaded_file'])) {
// Make sure the file was sent without errors
if($_FILES['uploaded_file']['error'] == 0) {
// Connect to the database
$dbLink = new mysqli('localhost', 'root', 'root', 'odt_db');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
// Gather all required data
$name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
$mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
$data = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name']));
$size = intval($_FILES['uploaded_file']['size']);
$custname = $_POST['custname'];
$delnoteno = $_POST['delnoteno'];
$delrefno = $_POST['delrefno'];
// Create the SQL query
$query = '
INSERT INTO `Annaveigh` (
`filename`, `filemimetype`, `filesize`, `filedata`, `filecreated`, `custname`, `delnoteno`, `delrefno`)
VALUES (
'$name', '$mime', $size, '$data', NOW(), '$custname', '$delnoteno', '$delrefno'
)';
// Execute the query
$result = $dbLink->query($query);
// Check if it was successfull
if($result) {
echo '';
}
else {
echo 'Error! Failed to insert the file'
. "<pre>{$dbLink->error}</pre>";
}
}
else {
echo 'An error accured while the file was being uploaded. '
. 'Error code: '. intval($_FILES['uploaded_file']['error']);
}
// Close the mysql connection
$dbLink->close();
}
else {
echo 'Error! A file was not sent!';
}
?>
Debug...
[attachment=0]Screen shot 2010-12-10 at 10.10.38.png[/attachment]