Phillips126
New Member
Hey All,
Question - perhaps you can answer this for me... as I'm not as code savvy as I'd like to be.
My site runs the uploadify script for its ease and it works great.
What I have it doing is uploading a single image, changing its name to a unique identifier (instead of the photo name) and then storing just the URL in a database to recall that image later on. Using the JavaScript "onUploadSuccess," I call out for the unique ID that was given to the image and place it in an input field, which will then be used to update the database.
See this image for a reference:
(Please Note - These top 2 fields are normally hidden away).
Ok, looks normal here... Uploading an image and obtaining the unique image ID is demonstrated on this image:
As you can see, the two hidden fields are populated, and the user is asked to fill the rest of the form out and submit it. The PHP code is set to look into the images table on the DB and update the remaining entries where the unique ID matches up.
Here is my PHP:
Here is the form HTML and JS:
If the PHP isn't asked to work until the submit button is pressed, and the field IS populated (even if by JS), why is the data not being seen?
My apologies for the code appearing quite unorganized - it does not look that way in Dreamweaver.
Thanks for your help!
Question - perhaps you can answer this for me... as I'm not as code savvy as I'd like to be.
My site runs the uploadify script for its ease and it works great.
What I have it doing is uploading a single image, changing its name to a unique identifier (instead of the photo name) and then storing just the URL in a database to recall that image later on. Using the JavaScript "onUploadSuccess," I call out for the unique ID that was given to the image and place it in an input field, which will then be used to update the database.
See this image for a reference:
(Please Note - These top 2 fields are normally hidden away).

Ok, looks normal here... Uploading an image and obtaining the unique image ID is demonstrated on this image:

As you can see, the two hidden fields are populated, and the user is asked to fill the rest of the form out and submit it. The PHP code is set to look into the images table on the DB and update the remaining entries where the unique ID matches up.
Here is my PHP:
PHP:
if (isset($_POST['submit'])) {
$file_id = $_POST['filename'];
$con = mysql_connect("localhost", "name", "pw") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
mysql_query("UPDATE images SET name = '" . $_POST['title']."',
info = '" . $_POST['info']."',
username = '" . $_POST['username']."'
WHERE id_num = $file_id");
mysql_close($con);
}
Here is the form HTML and JS:
HTML:
<form>
<div id="queue"></div>
<input id="file_upload" name="file_upload" type="file">
<input type="text" id="filename" name="filename" required="required" value="" />
<input type="text" name="username" disabled="disabled" required="required" value="<?php echo htmlentities($username); ?>" />
<label>Image Name</label>
<input type="text" class="span4" name="title" required="required" />
<label>Description</label>
<textarea type="text" class="span4" style="height:111px;" name="info" required="required"></textarea>
<input class="btn btn-primary" type="submit" name="submit" value="UPLOAD" />
</form>
Code:
<script type="text/javascript">
<?php $timestamp = time();?>
$(function() {
$('#file_upload').uploadify({
'formData' : {
'timestamp' : '<?php echo $timestamp; ?>',
'token' : '<?php echo md5('unique_salt' . $timestamp); ?>',
},
'multi' : false,
'removeCompleted' : false,
'uploadLimit' : 1,
'swf' : 'assets/uploadify.swf',
'uploader' : 'uploadify.php',
'onUploadSuccess' : function(file, data, response) {
document.getElementById('filename').value=data;
javascript:$('#file_upload').uploadify('disable', true);
}
});
});
</script>
If the PHP isn't asked to work until the submit button is pressed, and the field IS populated (even if by JS), why is the data not being seen?
My apologies for the code appearing quite unorganized - it does not look that way in Dreamweaver.
Thanks for your help!
Last edited: