can you run a query just by a button

e.g UPDATE DATABASE

when click the button have a query in it to automatically update a table in the database

Member Avatar for rajarajan2017

I am wondering! Why not! Create a button, write the relevant query in a function to execute it.

so

button is on a php file

Query is

SELECT loan WHERE bookid =$bookid
UPDATE loan.loan 'no'

but how do i set this in the button without opening another page?

Member Avatar for diafol

Nice link. Wise to get the low down on the ajax object. After getting thoroughly confused by the thing and creating apps that didn't work, I turned to Prototype, which deals with Ajax calls extremely well. I've since migrated to jQuery.

Member Avatar for diafol

Yep, nice one Will.

But can i not just put it in a button in the php and use mysql query??

Member Avatar for diafol

No, php is done once it leaves the server and the info is sent to the client (your browser). The user can interact with the page in 2 main ways: via javascript - the page can be changed without refresh (e.g. hiding or changing info on the page) - BUT no changes will occur on the server (db/files etc). Via page navigation (url or form submission). This is where php can do its stuff - this is where changes can be made to DB/files etc.

Ajax is a special case where a js script is run which can access a php script and change stuff on the server without the page having to be reloaded/re-accessed. It's not as simple as js trying to run a php script.

Sorry if it sounds confusing. 'Twas a heavy day yesterday!

ok i understand, i got it sorted thanks..took a while but got there :)

could you help with validation?

I have a form with the following:

enter book id : it a combo box of all book ids in the book table
Enter book name: combo box with all book names
book author: combo box with all book author

Could you tell me how as soon as the book id is selected into the form, the book name and author would authomatically appear that match that book id??

Hope im explaining this ok...If you could help it would be great! :)

This would be another AJAX routine. Get the value of the bookId selection then query the database to get the appropriate selection numbers to activate in the other boxes.

so set a query that takes the book name and book author that is entered in2 the bookid...totally confused in how i would do that??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.