mySQL query using script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kristolklp
Forum Commoner
Posts: 30
Joined: Mon Sep 05, 2005 2:24 pm

mySQL query using script

Post by kristolklp »

I would like to run a function when a user checks a checkbox to update a fields in a database. I know to call a function using 'onCLick' you have to write a function through script, however I am unsure how to or if you can then run a query in Javascript.

Will I need to use VBScript instead?

Any help (or a quick example) would be greatly appreciated.

Thanks.

*edit: sorry, i meant to post this in the database section.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

vbscript, nor any other client-side scripting language can do it. You would use the onclick to do a form submission with the important data to a script on the server that performs the action requested..
kristolklp
Forum Commoner
Posts: 30
Joined: Mon Sep 05, 2005 2:24 pm

Post by kristolklp »

oic...thanks for the quick reply.

How do i submit a form using onClick? This is how I was calling my function.

Code: Select all

<input type="checkbox" name="update" onClick="UpdateSetting();">

Is it as simple as doing:

Code: Select all

<input type="checkbox" name="update" onClick="document.formName.submit();">
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can do it in the function or like the latter.. it's quite flexible as to where you can do it..
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

No, I think Feyd is trying to tell you that the server needs to handle the processing not the client machine. That means that the onClick event will not generate the results you want because a client side script cannot interact with a database.

Process the form as normal and handle the database interaction with the server-side script.
kristolklp
Forum Commoner
Posts: 30
Joined: Mon Sep 05, 2005 2:24 pm

Post by kristolklp »

gotcha. thanks!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

kristolklp wrote:gotcha. thanks!
Just to clarify, there are two parts to your question. One that involves the submission of a form based on a clicke vent raised when a checkbox is checked (this is a client-side code question - Javascript). The other is what happens after the form is submitted (a server-side code question - PHP). I do not want to step on Feyd's toes with my previous answer.

The form submission can be handled in a number of ways, even using a text link to post back to the script. The actual processing of the data that was sent by the form being submitted is what needs to be handled on the server.
Post Reply