3 Replies - 293 Views - Last Post: 02 October 2012 - 11:52 AM Rate Topic: -----

#1 jaynajay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 17-September 12

Radio button not working

Posted 02 October 2012 - 11:01 AM

I get error message when i try to post this.


<?php


$intAssetHiddenTrue = "";


if ($_POST['hiddenTrue']) {
        
	$intAssetHiddenTrue = $_POST['hiddenTrue'];

?>

<input type="radio" name="hiddenTrue" value="True" />True<br />
<input type="radio" name="hiddenTrue" value="False" />False<br />



Is This A Good Question/Topic? 0
  • +

Replies To: Radio button not working

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3635
  • View blog
  • Posts: 5,756
  • Joined: 08-June 10

Re: Radio button not working

Posted 02 October 2012 - 11:35 AM

And what would that error message be? - It's one thing knowing there is an error, and a completely different thing knowing what that error is. PHP prints those messages for a reason.

I can tell you, however, that using a $_POST value that wasn't sent will generate a "Undefined index" notice.
/** Don't do this: **/
if ($_POST["key"]) {
    // Do stuff with key...
}

/** Do this: **/
if (isset($_POST["key"])) {
    // Do stuff with key...
}

/** Or, when appropriate, this: **/
if (!empty($_POST["key"])) {
    // Do stuff with key...
}


The last two there will both check if the key exists before trying to use it, thus avoiding said error notice. The last one will also verify that the key has a non-empty value, which the isset() function will not. Usually you'll want to use empty().
Was This Post Helpful? 0
  • +
  • -

#3 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 943
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: Radio button not working

Posted 02 October 2012 - 11:38 AM

Hey, you need to be more specific. We do not know what error message you are getting, you must tell us.

I can tell you this much however. If you want to check if a value exist in a variable then use either the isset or empty function. You should also have your INPUT elements within a FORM.
Was This Post Helpful? 0
  • +
  • -

#4 jaynajay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 17-September 12

Re: Radio button not working

Posted 02 October 2012 - 11:52 AM

I apologize for not posting the whole code here. Surprisingly, all I had to do was to copy/paste the entire code in a new file. It is working now.

Thanks both of you for the help, though! I sure will use this method suggested by you guys.

Did not mean to waste your time. Sorry!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1