I have two functions one is PHP second is JQuery. I want them to activate on same button click. But I want fisrt to activate PHP function and then JQuery. How can I do this. Here is my code. The problem is this line in JQuery function
var imagename = "<?php echo $nameoffile ?>";
When I replace that with hardcoded variable everything work fine. How can I control order of execution ?
HTML :
<form id ="submit_leave_email" enctype="multipart/form-data" method="POST" >
<div class="form1">
<div class="radio-line" id="radio-manager" style="font-size:12px">
<input type="radio" id="rad-400" name="radio-manager" value="No"/> Registered
<input type="radio" id="rad-400" name="radio-manager" value="No"/> Unregistered
</div> <br>
<h4 class="manager" style="font-size:12px">ID of car is :</h4><br><br>
<input type="hidden" name="MAX_FILE_SIZE" value="100000" class="input_1" />
<input id="fileupload" name="uploadedfile" type="file" class="input_1" /><br/>
<input id="brand" type="text" value="Name of car :" class="input_1" name="brand" /><br></div> <br>
<div id = "image" style="width:100px; height:100px"></div></div>
<input id="submit" type="submit" name="submit" value="submit">
</form>
PHP :
<?php
if(isset($_POST['submit'])){
$target_path = "images/";
$nameoffile = basename( $_FILES['uploadedfile']['name']);
$target_path = $target_path . $nameoffile;
echo $nameoffile;
if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "There was an error uploading the file, please try again!";
}
}
?>
JQuery :
<script type="text/javascript">
$( "#submit_leave_email" ).submit(function( event ) {
var brand = $('#brand').val();
var id = localStorage.getItem("id");
if($('#rad-400').is(':checked')){
var ide = 'reg';
} else {
var ide = 'unreg';
}
var imagename = "<?php echo $nameoffile ?>";
$.ajax({
type: "POST",
url: "updateCarSql.php",
data: "ide=" + ide + "&id="+ id + "&brand="+
brand+"&imagename="+imagename,
success: function(){
$("#submit_leave_email").fadeOut();
$("#update_success1").fadeIn();
}
});
});
</script>