below I have an iframe which deals with a file input:
var $fileVideo = $("<form action='videoupload.php' method='post' enctype='multipart/form-data' target='upload_target_video' onsubmit='return videoClickHandler(this);' class='videouploadform' >" +
"Video File: <input name='fileVideo' type='file' class='fileVideo' /></label>" +
"<input type='submit' name='submitVideoBtn' class='sbtnvideo' value='Upload' /></label>" +
"<p class='listVideo' align='left'></p>" +
"<iframe class='upload_target_video' name='upload_target_video' src='/' style='width:0px;height:0px;border:0px;solid;#fff;'></iframe></form>");
Now I have a function below where when the file has stopped uploading and has successfully uploaded into the server, it will display the name of the file uploaded:
function stopVideoUpload(success, videofilename){
var result = '';
videocounter++;
if (success == 1){
result = '<span class="videomsg'+videocounter+'">The file was uploaded successfully</span>';
$('.listVideo').eq(window.lastUploadVideoIndex).append('<div>' + htmlEncode(videofilename) +
'<input type="text" name="videoidhide" value=""/><br/><hr/></div>');
}
return true;
}
You will also see that there is a text input next to the file name. This is relevant to my question.
Below is the php script the frame links to videoupload.php and this script will upload the files and insert the data into the database:
move_uploaded_file($_FILES["fileVideo"]["tmp_name"],
"VideoFiles/" . $_FILES["fileVideo"]["name"]);
$result = 1;
$videosql = "INSERT INTO Video (VideoFile)
VALUES (?)";
if (!$insert = $mysqli->prepare($videosql)) {
// Handle errors with prepare operation here
}
//Dont pass data directly to bind_param store it in a variable
$insert->bind_param("s",$vid);
//Assign the variable
$vid = 'VideoFiles/'.$_FILES['fileVideo']['name'];
$insert->execute();
if ($insert->errno) {
// Handle query error here
}
$insert->close();
?>
<script language="javascript" type="text/javascript">
window.top.stopVideoUpload(<?php echo $result; ?>, '<?php echo $_FILES['fileVideo']['name'] ?>');
</script>
Below is an example database showing the insert of the file:
Video_Question Table:
VideoId (PK auto) VideoFile
1 VideoFiles/carrace.mp4
2 VideoFiles/cricket.mov
Now what my question is that where you see in the mysqli code where it inserts the uploded video file into the VideoFile field in the db, how can I retrieve the value from the VideoId field and display it in the text input for each associated uploaded file?
For example if carrace.mp4 was uploaded, then retrieve the VideoId 1 from the db and display it in the text input next to the name of the uploaded file.
Just call
$mysqli->insert_idand append it to the file name before you call thefunction stopVideoUploadAlso
$vidneeds to be assigned before you bind it, not after