Jump to content

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


gaffafoote

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.