August 19, 201016 yr Hi there, i have 2 radio buttons with seperate options but both are for the same table row. However, no matter what option i choose, the value of the radio picked will not add to the database.. Here is what i have. Pick option <form method="post" action="index.php"> <input type="hidden" name="add" value="true" /> <input type="radio" name="okay" id="color12" value="one" /> On <input type="radio" name="okay" id="color12" value="two" /> Off<br/><br/> <input type="submit" name="submit" value="submit" /> </form> PHP behind it. function addcss($p) { $color12 = $_REQUEST['color12']; $sql = "INSERT INTO stylesheet VALUES ('$color12')"; $res = mysql_query($sql) or die(mysql_error()); echo "Stylesheet Added Successfully"; } //end post Thanks in Advance.
August 19, 201016 yr Hi, First off, always escape data you'r putting into a query string, unless you like getting hacked The reason it's not working is because the REQUEST array, along with GET and POST, is indexed by the 'name' attribute of the form element, not the ID. Also, ID attributes in html must always be unique on that page. The correct code (complete with mysql escape in place) is: $color12 = mysql_real_escape_string($_REQUEST['okay']); $sql = "INSERT INTO stylesheet VALUES ('$color12')";
August 19, 201016 yr Author Hi, First off, always escape data you'r putting into a query string, unless you like getting hacked The reason it's not working is because the REQUEST array, along with GET and POST, is indexed by the 'name' attribute of the form element, not the ID. Also, ID attributes in html must always be unique on that page. The correct code (complete with mysql escape in place) is: $color12 = mysql_real_escape_string($_REQUEST['okay']); $sql = "INSERT INTO stylesheet VALUES ('$color12')"; Great that worked nicely. Now how can i have the radio form say: if this one is selected > [1] - then use this text field [text] or if this one is selected > [2] - then use this text field instead [text2] Thanks again for previous.
Create an account or sign in to comment