Jump to content

sending 2 values from a radio button to two different MySQL columns


gaffafoote

Recommended Posts

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
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
Gareth,

This is as simple as including an if statement in your php code.

[code]<?php
// Check the value of the radio button
if (isset($_POST['radio_button_name'])){
  $r = $_POST['radio_button_name'];
}

// Decide what to do with it
if ($r == "male"){
  $sql = "INSERT INTO table_name (column_1) VALUES ('$r')";
}
else {
  $sql = "INSERT INTO table_name (column_2) VALUES ('$r')";
}

// Run the query
mysql_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.

Regards
Huggie
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.