the user must select their gender and then it is sent to the database

Please tell me how to make one of the two selected options go.

<label for="male1">Mr</label> <input type="radio" name="gender" id="sendMale" value="MR" checked="checked"> <label for="female">Mrs</label> <input type="radio" name="gender" id="sendFemale" value="MRS"> <input type="submit" value="send" id="send"> $gender= $_REQUEST['gender']; $insert_sql = "INSERT INTO tickets (`gender`, ...) VALUES ('$gender',...)"; $insert= mysql_query($insert_sql); $("#send").click(function () { var myData = //"mail=" + $("#sendMail").val() + что-то вроде "&gender=" + $("#sendMale").val(); jQuery.ajax({ type: "POST", url: "../php/insert.php", dataType:"text", data:myData, success:function(response){ //дальше неважно что }); }); 
  • Bring a php script handler. Or try to do it yourself and then bring if something does not work. - Naumov

2 answers 2

Well, yes, the client part can be, for example, such (call by name, and use json format for data transfer)

 <label for="male1">Mr</label> <input type="radio" name="gender" id="sendMale" value="MR" checked="checked"> <label for="female">Mrs</label> <input type="radio" name="gender" id="sendFemale" value="MRS"> <input type="submit" value="send" id="send"> $("#send").click(function () { var gender = $('[name="gender"]:checked').val(); var myData = {gender: gender}; $.ajax({ type: "POST", url: "../php/insert.php", dataType: "json", data: myData, success: function(response) { //дальше неважно что } }); }); 
  • there is one big BUT. I need var myData to look something like this: var myData = "first =" + $ ("# sendFirst"). val () + "& last =" + $ ("# sendLast"). val () - Oblivion
  • If it is in the text format, then simply substitute the name value in the var myData = "mail=" + $("#sendMail").val() + "&gender="+ $('[name="gender"]:checked').val(); - Daniel-664
  • @ Daniel-664 thanks a lot! worked) - Oblivion
  • Not at all, please contact) - Daniel-664
  • please do not tell me how to do without using var myData? that is, to immediately write to data as follows: {'first': $ ('# sendFirst'). val (), - Oblivion
 var selected = $('input[name=gender]:checked').val(); if (selected.length > 0){ myData = selected.val(); } 
  • hmm, it doesn't work - Oblivion