SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    newbie validation

    Hi,

    I have a form that I am building. It has radio buttons in it. I am placing info into mysql. The form calls the form process script. In the top of the process script I have the variables...

    Code:
    $usCitizen = $_POST['newusCitizen'];
    I want to set this to that if it is not required to click the radio button the form will process and not give me this error...

    Undefined variable: usCitizen in /www/content/html/test/signup_process.php on line 85

    I think trying isset might work but need a little help.

    Code:
    if(isset($_POST['newus_citizen'])) {
       $usCitizen == 0;
    }
    If you can help that would great!
    Thank you
    tim

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2009
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may need to change your PHP configuration. If possible, add this line to php.ini

    error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
    Daniel, Helpdesk Leader
    Hosting24.com Web Hosting - First class web hosting services.
    Reseller Hosting - Provide unlimited disk space and bandwidth

  3. #3
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hosting24, it's worst advise that could be ever.
    Don't be silly. Error messages are NOT for eliminating them. But to READ and CORRECT them.
    If you didn't know.

    timwhelan, you've almost did it
    PHP Code:
    if(isset($_POST['newus_citizen'])) {
      
    $usCitizen $_POST['newusCitizen'];
    } else {
       
    $usCitizen == 0;


  4. #4
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The Test server I am on is set up to show all errors. Not sure how that would help.
    If I check a radio button it doesn't show the Undefined variable.

    Thanks!

    ***
    Shrapnel - Saw yours after I posted. Will test. Thank you!

  5. #5
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Showing all errors will help you thousand times. No less.

  6. #6
    SitePoint Evangelist
    Join Date
    Aug 2009
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shrapnel_N5, you can say that to PHP script developers. If PHP is configured to display absolutely all errors, many scripts (even coded by well known companies) bother webmasters with error messages like this...
    Daniel, Helpdesk Leader
    Hosting24.com Web Hosting - First class web hosting services.
    Reseller Hosting - Provide unlimited disk space and bandwidth

  7. #7
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hosting24, say it to those webmasters. With their scripts.
    But here are no webmasters. Here is programmer. Who writes from scratch.
    Do not make that bad practice repeated again. But encourage others for good practice instead. Isn't it obvious?

  8. #8
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hosting24 View Post
    You may need to change your PHP configuration. If possible, add this line to php.ini

    error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
    While in development mode always work with:
    error_reportin(E_ALL)
    if for PHP5 strict checking you can also use E_STRICT.
    Good practice always counts

  9. #9
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not only in development mode.
    If code was developed under E_ALL, why change it on production server?

  10. #10
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    Not only in development mode.
    If code was developed under E_ALL, why change it on production server?
    As long as you mean logging rather than showing errors to users, yes. You can't test every scenario that might arise in development, if you could, we would have bug free code everywhere :P

  11. #11
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I mean logging of course.
    There was no question on "what to do" with error messages.
    Only on level of error reporting.
    which always should be as high as possible.

  12. #12
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, definitely agree then, thought you might have meant that because dev server is error free, prod server will be also, my bad.

  13. #13
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hash View Post
    As long as you mean logging rather than showing errors to users, yes. You can't test every scenario that might arise in development, if you could, we would have bug free code everywhere :P
    That's one obvious reason not to use E_ALL mode in production server.
    Rather we can log errors or mail errors while in production mode.

  14. #14
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHPycho, you messed it up
    It is very common misunderstanding though.
    With error_reporting(0) you wouldn't get one single error message in your mail or log. So, it leads to disaster.
    E_ALL means which error message will be generated. Not where it goes.

    Error reporting shouldn't be changed on production. Just don't touch it.
    Take a look on display_errors directive, which, I believe, you were meant.

  15. #15
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Another way of fixing the problem without changing the PHP at all is to add a hidden input field before the first radio button with the same name as the radio buttons and the default value you want the field to have if no radio button is selected.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  16. #16
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Another way of fixing the problem without changing the PHP at all is to add a hidden input field before the first radio button with the same name as the radio buttons and the default value you want the field to have if no radio button is selected.
    That's perfect (y)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •