Jump to content


Photo

execute php from javascript


  • Please log in to reply
9 replies to this topic

#1 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 26 February 2006 - 07:07 PM

I have a form that is filled in and each part that has something done to it i want added to a database on my server, for that user.

I have a onchange=update() in my form and this would then call the script to update the database.

is this possible.

or is there another way i can do this.

i tried to use in the update.js file


function update()
{
<?
echo("hello");
?>
}

just to see if anything happen, and it did not.

how can i execute php while in a js file?

is there another way to do this?

thanks you in advance for your help.


Jason

#2 phpfreak101

phpfreak101
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 26 February 2006 - 07:40 PM

php is executed on the server and then the code that is outputted by the php code, is added to your site's HTML. After a user views your website, the php has already been executed and the output writen to your site. If you need to pass information to a php file after the user has viewed your site you can set up a hidden or visible textbox form with HTML, and send the POST values (or the values of each form element after the user has 'posted' the form) to another php file.

Set your form "action" to the next php file you want to pass the variables to, and then you can use $_POST['html form element name'] THis is your form element value.

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 26 February 2006 - 09:36 PM

You can now use the new(ish) AJAX techniques to do this. There is a forum on this site for AJAX questions along with a sister site [a href=\"http://www.ajaxfreaks.com/\" target=\"_blank\"]AJAXfreaks[/a].

Ken

#4 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 26 February 2006 - 10:58 PM

my page has lots of options and i want to be sure that the selection are kept in case they lose their connection of what ever.

each person has a login name and password.

while they make their selection i want the database updated on each change, so that they can come back later to finish off, without having to full out everything from the start again.

how else can i do this?

Thanks

Jason

#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 26 February 2006 - 11:44 PM

Use javascript to store the values in a cookie.

[a href=\"http://www.w3schools.com/js/js_cookies.asp\" target=\"_blank\"]http://www.w3schools.com/js/js_cookies.asp[/a]

Then when they come back to the site, you should be able to retrieve the vars in either php or javascript.

#6 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 26 February 2006 - 11:54 PM

Hi,

Thanks for a quick response.

Yes i know i could use cookies, but want to make this as streamlined as possible.

i know as i do myself, disable cookies from being stored on my pc, this is why i would like to have it stored in the database.

how else can i do this?


Jason

#7 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 27 February 2006 - 12:00 AM

Your only other option for storing each field as they are entered is ajax.

#8 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 27 February 2006 - 08:46 AM

[!--quoteo(post=349702:date=Feb 27 2006, 12:00 AM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Feb 27 2006, 12:00 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Your only other option for storing each field as they are entered is ajax.
[/quote]

your say ajax, but what am i looking for?

i have posted my question there.

thanks

Jason

#9 tim_perrett

tim_perrett
  • Members
  • Pip
  • Newbie
  • 9 posts
  • LocationBath, UK

Posted 27 February 2006 - 09:53 AM

AJAX it is, thats the only way you will do that....

www.ajaxfreaks.com

Tim Perrett
[!--coloro:gray--][span style="color:gray"][!--/coloro--][!--fonto:Arial--][span style="font-family:Arial"][!--/fonto--][!--sizeo:1--][span style="font-size:8pt;line-height:100%"][!--/sizeo--]Tim Perrett[!--sizec--][/span][!--/sizec--]

-- PHP 5.1 --
-- Ruby 1.8.4 / Rails 1.1 --
-- LigHTTPD 1.4.1 --
-- FastCGI -- -- Apache 2.0.2 -- -- Apple OSX -- -- Linux: FC5 / SUSE -- -- JavaScript -- -- Objective C -- -- CGI / Perl -- -- MySQL 5 -- -- PostGre SQL -- -- Java (Spring) -- -- Unix -- -- Win32 -- "90% of being smart is knowing what you're dumb at." [!--colorc--][/span][!--/colorc--][!--fontc--][/span][!--/fontc--]

#10 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 27 February 2006 - 11:32 AM

[!--quoteo(post=349788:date=Feb 27 2006, 09:53 AM:name=tim_perrett)--][div class=\'quotetop\']QUOTE(tim_perrett @ Feb 27 2006, 09:53 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
AJAX it is, thats the only way you will do that....

www.ajaxfreaks.com

Tim Perrett
[/quote]

ajax is a forum with some help pages with scripts.
what an i actually looking for on this site.
a link would be helpfull to an idiot like me.
i am not very bright!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users