Hi
i m learning PHP.How can i insert a data in mysql by using onchange event in radio button, i m not used a submit button in my code can u help me by giving a solution of my prolblem by giving a little example.

Thank you so much

Recommended Answers

All 3 Replies

You have to use a Javascript (or jQuery) AJAX to call a PHP script to perform a MySQL insert.

This is pretty straight-forward and is usually easier than most people think. What I would do is call a function in the onchange attribute. In the following example the onchange attribute will be watching a dropdown, so the function will be called upon when the value of the dropdown changes:

<select onchange="myFunction()">

Then in my script I could have a javascript function with a jQuery AJAX block:

function myFunction(){
    $.ajax({url:"script.php", success:function(result){

        something here to output the result, like a div update.

    }});
}

Then in script.php validate and execute your SQL query. The need to call upon another script arises from Javascripts inability to communicate with the server, unless you're using node.js, which is a totally different kettle of fish. Javascript is a client side language and everything it does is completed in the users browser. By using jQuery's Ajax we can call upon a server side script from the users browser when a change is made.

I hope this makes sense, but I didn't have much from you to work with.

See more: http://api.jquery.com/jquery.ajax/

Regards,
M

You have to use a Javascript (or jQuery) AJAX to call a PHP script to perform a MySQL insert.

Sorry Pritaeas - you posted your response whilst I was typing mine :)

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.