Jump to content

Passing Variable from one code to another..


anthelo

Recommended Posts

Hello, i need some help from the experts.

 

This is the code where im uploading the image on the server

<script type="text/javascript" >
$(function(){
	var btnUpload=$('#upload');
	var status=$('#status');
	var uploadingfile;
	new AjaxUpload(btnUpload, {
		action: 'lib/image-store.php',
		name: 'uploadfile',
		onSubmit: function(file, ext){
			 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
                    // extension is not allowed 
				alert('Only JPG, PNG or GIF files are allowed');
				return false;
			}
			status.text('Uploading...');
		},
		onComplete: function(file, response){
			//On completion clear the status
				alert('Image Uploaded');

			//Add uploaded file to list
			if(response==="success"){
				$('<li></li>').appendTo('#files').html('<img src="./uploads/'+file+'" alt="" /><br />'+file).addClass('success');
			} else{
				$('<li></li>').appendTo('#files').text(file).addClass('error');
			}
		}
	});

});
</script>

 

Here is the code where i submit the data on the server

<script type="text/javascript">

$("#CSubmit").click(function(e) {

	e.preventDefault(); 
    	var $form = $("#CForm"),
        fname	= $form.find('input[name="fname"]').val(),
        sname	= $form.find('input[name="sname"]').val(),
	email 	= $form.find('input[name="email"]').val(),
	phone 	= $form.find('input[name="phone"]').val(),
	uid 	= $form.find('input[name="uid"]').val(),
	description 	= $form.find('textarea#description').val(),
	url 	= $form.attr('action');

	$.ajaxSetup({async: false});
	$.post('lib/user-store.php', 
	{ fname: fname, sname: sname, email: email, phone: phone, description: description, uid: uid },
		function(data) {
			if (data == 'ok') {
				$('#div1').hide();
				$('#div2').show();
  alert(uploadingfile);

			}
		});

return;

 });
</script>

 

Both of the are working, what i want to do is when uploading an image (code 1) to get the file name and submit them on mysql like the rest of the data (code 2)

 

Regards

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.