Hi everyone!
i have a question that, if there are two radio buttons Male and Female, if some select male,this value will be store into database, but if he select again another value which is female,then how the first value(Male) will be replace by second value (Female) in the database using PHP and Ajax, please give me an easy solution

Re: Radio buttons value reset in database with Ajax and php 80 80

Depends how you are storing the data. If a person has to log in then you search for the users id in the table. If it doesn't exist, add the record, if it exists, edit the record. There are queries that will do this in one go.
If you do not have a login, you could alter the table to include the session variable and treat that as the id. Obviously the session var will change between sessions. Any more info? Table structures?

Re: Radio buttons value reset in database with Ajax and php 80 80

Here's the steps you might take to implement this:

  • Create a web page with a <form> and two radio buttons, one for male, and one for female
  • Use jQuery because it's the simplest way to do AJAX
  • Write a jQuery method such that clicking on a radio button makes an AJAX POST request to a php file on your server
  • Write a PHP script which accepts $_POST data and sees whether male or female was submitted via the AJAX request
  • Create a MySQL database to store whether a male or female value is checked
  • Use a PHP MYSQLi client library to connect to the database from within your PHP script
  • Depending on the value in the $_POST data, use the MySQLi client to update the database with the appropriate value

Good luck!

Be a part of the DaniWeb community

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