Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 22nd Aug 2012, 03:26 AM   #1
Active Warrior
 
Join Date: 2011
Posts: 44
Thanks: 3
Thanked 1 Time in 1 Post
Default
upload pic and insert different values in database using jquey...
Share on: 
fb share twitter share gplus share more share

Hello

I wanna update my database and upload picture in my folder after rename the pic but the problem is when i tried to send simple value get from text fields,radio button and check box its working fine but when i wanna upload pic using this it not working

code is here

<input type="text" name="film_title" size="45" id="film_title"/>
<input type="text" name="film_release_date" id="film_release_date" />
<input type="radio" name="film_industry_language" value="Urdu" id="Urdu" class="film_industry_language" /><label for="Urdu">Urdu</label>
<input type="checkbox" name="film_genre[]" value="Action" id="Action" class="film_genre" /><label for="Action">Action</label>
<input type="checkbox" name="film_genre[]" value="Adventure" id="Adventure" class="film_genre"/><label for="Adventure">Adventure</label>
<input type="file" size="50" name="film_image" id="film_image"/>

<input type="submit" value="submit whole film info" name="submit" id="save_button" class="submitm"/><span id="save_status"></span>


<script language="javaScript" type="text/javascript" src="js/jquery.js"></script>
<script language="javaScript" type="text/javascript">
$('#save_button').click(function(){
var film_title = $('#film_title').val();
var film_release_date = $('#film_release_date').val();
var film_industry_language = $('.film_industry_language').val();
var film_image = $('#film_image').val();
var film_genre="";
film_genre += $('#Action').val() + "\n";
film_genre += $('#Adventure').val() + "\n";
film_genre += $('#Animation').val() + "\n";
film_genre += $('#Biography').val() + "\n";

$('#save_status').text('Loading...');

$.post('ajax/add-new-film-form-ajax.php',{ film_title: film_title , film_release_date:film_release_date , film_industry_language:film_industry_language, film_genre:film_genre, film_image:film_image }, function(data){
$('#save_status').text(data);


});
});
</script>


i don't wanna us <form> because when i use this <form> refresh my page can anyone help me to get image_name, image_tmp name..

Thanks

lovefax89 is offline  
Unread 22nd Aug 2012, 01:41 PM   #2
Software Engineer
War Room Member
 
wayfarer's Avatar
 
Join Date: 2008
Location: Asheville, NC USA
Posts: 693
Thanks: 37
Thanked 112 Times in 100 Posts
Default
Re: upload pic and insert different values in database using jquey...
Share on: 
fb share twitter share gplus share more share

You can't upload a picture using AJAX, it's not allowed. You have to use a form that submits through a hidden IFRAME.

Code:
<form action="ajax/add-new-film-form-ajax.php" method="post" enctype="multipart/form-data" rel="nofollow" target="hiddenframe">
...
</form>
<iframe name="hiddenframe" style="height: 1px; width: 1px; border: none; visibility: hidden;"></frame>
That's the basic idea. Notice that the target attribute of the FORM matches the name of the IFRAME. It's a little tricky reading the response though. It's best to use the iframe's onload() or $(iframe).load() event to determine when it has finished loading, then read its response with JavaScript. I think there's some plugins that will handle this already though. Google "AJAX upload" to find some.

I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
wayfarer is offline  
Unread 22nd Aug 2012, 06:56 PM   #3
Social Apps Made Easy
War Room Member
 
FirstSocialApps's Avatar
 
Join Date: 2012
Location: Mooresville, NC
Posts: 913
Thanks: 231
Thanked 259 Times in 213 Posts
Default
Re: upload pic and insert different values in database using jquey...
Share on: 
fb share twitter share gplus share more share

In your upload code you can run a JS on the top (the main page that has the IFRAME) when the upload is done. Let me know if you need a code snipit.

FirstSocialApps is offline  
Unread 23rd Aug 2012, 07:03 AM   #4
Active Warrior
 
Join Date: 2011
Posts: 44
Thanks: 3
Thanked 1 Time in 1 Post
Default
Re: upload pic and insert different values in database using jquey...
Share on: 
fb share twitter share gplus share more share

Originally Posted by wayfarer View Post

You can't upload a picture using AJAX, it's not allowed. You have to use a form that submits through a hidden IFRAME.

Code:
<form action="ajax/add-new-film-form-ajax.php" method="post" enctype="multipart/form-data" rel="nofollow" target="hiddenframe">
...
</form>
<iframe name="hiddenframe" style="height: 1px; width: 1px; border: none; visibility: hidden;"></frame>
That's the basic idea. Notice that the target attribute of the FORM matches the name of the IFRAME. It's a little tricky reading the response though. It's best to use the iframe's onload() or $(iframe).load() event to determine when it has finished loading, then read its response with JavaScript. I think there's some plugins that will handle this already though. Google "AJAX upload" to find some.
thanks for helping me..now its working fine but now i have one more small problem

I wanna redirect my use to his/her post she/he just make but when i use iframe he show my threat down my form page...
help me in this how can i redirect use to require page on same tab

Regards

lovefax89 is offline  
Unread 23rd Aug 2012, 08:02 AM   #5
Software Engineer
War Room Member
 
wayfarer's Avatar
 
Join Date: 2008
Location: Asheville, NC USA
Posts: 693
Thanks: 37
Thanked 112 Times in 100 Posts
Default
Re: upload pic and insert different values in database using jquey...
Share on: 
fb share twitter share gplus share more share

I'm not quite sure what you mean. Could you rephrase?

I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
wayfarer is offline  
Unread 23rd Aug 2012, 09:22 AM   #6
Active Warrior
 
Join Date: 2011
Posts: 44
Thanks: 3
Thanked 1 Time in 1 Post
Default
Re: upload pic and insert different values in database using jquey...
Share on: 
fb share twitter share gplus share more share

in php we use this for redirection
Header("Location: abc.php");

but when i use this in my ajax/add-new-film-form-ajax.php to redirect my page my page redirecting but it only showing the container of iframe and my form is also showing
I wanna show only my new page created by form using this form on same tab

lovefax89 is offline  
Unread 23rd Aug 2012, 11:54 AM   #7
Software Engineer
War Room Member
 
wayfarer's Avatar
 
Join Date: 2008
Location: Asheville, NC USA
Posts: 693
Thanks: 37
Thanked 112 Times in 100 Posts
Default
Re: upload pic and insert different values in database using jquey...
Share on: 
fb share twitter share gplus share more share

First of all, when you send a header, that only happens before the rest of your output is sent, so you can't redirect that way. You'll need to do something on the client-side, with JavaScript, etc, but without knowing more about your system it's hard for me to give advice about it.

I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
wayfarer is offline  
Closed Thread


Bookmarks

Tags
database, insert, jquey, pic, upload, values


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 01:46 AM.