gaffafoote Posted January 12, 2007 Share Posted January 12, 2007 Hi there,I have a beginners question regarding sending values from a radio button to my MySQL columns. I need the radio button to have two values which will then be sent to seperate columns in my MySQL table.That's it in a nutshell!Cheers,Gareth. :o Quote Link to comment https://forums.phpfreaks.com/topic/33870-sending-2-values-from-a-radio-button-to-two-different-mysql-columns/ Share on other sites More sharing options...
scottybwoy Posted January 12, 2007 Share Posted January 12, 2007 Can you include the code of you radio button. And will the values be static. You can use name=1stValue value=2ndValue in the radiocode then when it's sent to the php break down the $_POST var by $secondVal = $_POST['1stValue'] then extract the key using something from the manual >> http://fr3.php.net/manual/en/ref.array.php Quote Link to comment https://forums.phpfreaks.com/topic/33870-sending-2-values-from-a-radio-button-to-two-different-mysql-columns/#findComment-158972 Share on other sites More sharing options...
HuggieBear Posted January 12, 2007 Share Posted January 12, 2007 Gareth,This is as simple as including an if statement in your php code.[code]<?php// Check the value of the radio buttonif (isset($_POST['radio_button_name'])){ $r = $_POST['radio_button_name'];}// Decide what to do with itif ($r == "male"){ $sql = "INSERT INTO table_name (column_1) VALUES ('$r')";}else { $sql = "INSERT INTO table_name (column_2) VALUES ('$r')";}// Run the querymysql_query($sql);?>[/code]However, this could be a sign of bad database design, it's difficult to tell without knowing the context of the post.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33870-sending-2-values-from-a-radio-button-to-two-different-mysql-columns/#findComment-158976 Share on other sites More sharing options...
gaffafoote Posted January 12, 2007 Author Share Posted January 12, 2007 Thanks for your comments.I am using php and mysql to allow the user to control some basic elements of the page layout through css. A small graphic next to each radio btn will represent two values; for example text colour and background colour for a certain div. These will be sent to the MySql table and then echo'ed to another page.I hope that is clearer.You may have underestimated my lack of php knowledge. I am currently in pre-production and am trying to predict probelms i'm going to have, so haven't written the code yet. When I have i will post it and ask again.Cheers,Gareth. Quote Link to comment https://forums.phpfreaks.com/topic/33870-sending-2-values-from-a-radio-button-to-two-different-mysql-columns/#findComment-159056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.