Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Insert values of Radio form into mysql

Featured Replies

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.

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')";

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.