Please use error_reporting(E_ALL)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • matty

    #1

    Please use error_reporting(E_ALL)

    Just a couple of quick comments:

    In some of the CSS/DOM mailing lists I'm on, people generally
    refuse to help unless the HTML and CSS will validate. You
    can check these at http://validator.w3.org/check/ and
    http://jigsaw.w3.org/css-validator/check/ respectively, and it will
    often sort out problems you are experiencing with layout/display if
    your code validates properly.

    This has led me to think of things that could be done in here, to reduce
    the number of "easily fixed" posts. A lot of the problems that people in
    this newsgroup tend to experience would have been easier to solve
    if they did these things:

    - put error_reporting (E_ALL); in all your code. If you have a globally
    included/required file, stick it in the start there. Most of your
    problems will become easier to identify.

    You will probably find that you get problems with
    Notice: undefined index in ....
    Fix these by doing
    if (array_key_exis ts('myvar', $_POST))
    {
    // do stuff with $_POST['myvar']
    }
    etc

    - turn register_global s OFF. Use $_POST['variablename'] rather than
    $variablename for form data. Similarly use $_GET, $_FILES, $_SERVER, $_SESSION, etc.
    Your code will work on more servers, with less work, and you'll have a better handle
    on where the data is coming from. Probably better to avoid $HTTP_POST_VARS if you
    have a sufficiently current version of PHP; if you don't, better to use
    $HTTP_POST_VARS['myvar'] than $myvar

    - Check the value of mysql_error() if queries fail:
    if (!($result = mysql_query($sq l, $connection)))
    {
    print "Couldn't execute the query\n<pre>$sq l</pre>\nMySQL error is \n".mysql_error ();
    }

    - If you need to make a function call that could result in an error, you can always prefix
    it with @ :
    if (!@move_uploade d_file($somefil e, $someotherfile) )
    {
    // clean up here
    }

    - Check your query result has data in it, before fetching arrays/rows from it:
    either do
    if (mysql_num_rows ($result))
    {
    // do stuff
    }

    or

    while ($row = mysql_fetch_ass oc($result))
    {
    // do stuff
    }

    - If necessary, make sure you use addslashes(0 on data before putting it into an SQL query

    - Escape entities in HTML code (htmlentities() , urlencode() for URL query strings, etc)

    - If your form post/file upload handlers aren't working, try doing
    var_dump($_POST ) or var_dump($_FILE S) to see what input you're getting

    Also, if you get a strange or incomprehensibl e error message, it's often quite
    productive to try searching for the "standard" part of it in google, enclosed in quotes,
    e.g. http://www.google.com/search?q=%22un...sql_connect%22

    Anyone else think of any more?

    I'm not trying to be nasty; it's just that following some basic checks will allow
    you to find your errors more quickly and easily, and you'll start writing more
    robust code as a result!

    Matt
  • André Næss

    #2
    Re: Please use error_reporting (E_ALL)

    matty:
    [color=blue]
    > Just a couple of quick comments:
    >
    > In some of the CSS/DOM mailing lists I'm on, people generally
    > refuse to help unless the HTML and CSS will validate. You
    > can check these at http://validator.w3.org/check/ and
    > http://jigsaw.w3.org/css-validator/check/ respectively, and it will
    > often sort out problems you are experiencing with layout/display if
    > your code validates properly.
    >
    > This has led me to think of things that could be done in here, to reduce
    > the number of "easily fixed" posts. A lot of the problems that people in
    > this newsgroup tend to experience would have been easier to solve
    > if they did these things:[/color]

    You're probably right, problem is they don't come here until they experience
    the problem, and they clearly haven't got the slighest clue about how to
    use Google Groups.

    But as long as someone's willing to help I guess it's ok, but I've simply
    stopped answering most of these simple questions.

    André Næss

    Comment

    • matty

      #3
      Re: Please use error_reporting (E_ALL)

      André Næss wrote:

      [color=blue]
      >
      > You're probably right, problem is they don't come here until they
      > experience the problem, and they clearly haven't got the slighest clue
      > about how to use Google Groups.
      >
      > But as long as someone's willing to help I guess it's ok, but I've simply
      > stopped answering most of these simple questions.
      >
      > André Næss[/color]

      Maybe we need a FAQ...

      Comment

      • André Næss

        #4
        Re: Please use error_reporting (E_ALL)

        matty:
        [color=blue]
        > Maybe we need a FAQ...[/color]

        We certainly do, and the topic has been discussed before, but someone simply
        has to do it :/ A Wiki is maybe an even better idea as it makes it simple
        for many people to cooperatively develop it.

        André Næss

        Comment

        • matty

          #5
          Re: Please use error_reporting (E_ALL)

          Agelmar wrote:
          [color=blue]
          > matty wrote:[color=green]
          >> André Næss wrote:
          >>
          >>[color=darkred]
          >>>
          >>> You're probably right, problem is they don't come here until they
          >>> experience the problem, and they clearly haven't got the slighest
          >>> clue about how to use Google Groups.
          >>>
          >>> But as long as someone's willing to help I guess it's ok, but I've
          >>> simply stopped answering most of these simple questions.
          >>>
          >>> André Næss[/color]
          >>
          >> Maybe we need a FAQ...[/color]
          >
          > Matty, it's the same problem. People who are asking FAQ-type questions
          > (e.g. register_global s questions, mysql insert / update questions, etc.)
          > typically do not read the group before posting and/or look for the answer
          > anywhere else.[/color]

          Well, I'll put my site back up in a week or two - if anyone has any other
          suggestions for a FAQ, stick em in here (or email them to me) and I'll put
          them in!

          Comment

          • matty

            #6
            Re: Please use error_reporting (E_ALL)

            André Næss wrote:
            [color=blue]
            > matty:
            >[color=green]
            >> Maybe we need a FAQ...[/color]
            >
            > We certainly do, and the topic has been discussed before, but someone
            > simply has to do it :/ A Wiki is maybe an even better idea as it makes it
            > simple for many people to cooperatively develop it.
            >
            > André Næss[/color]


            Don't know if I'd be prepared to do a Wiki - too many wiki terrorists around.
            Maybe something with a confirmed email registration - I'll have a think. In
            general, what would people want to see, beyond standard faq/wiki stuff?

            Comment

            • Jochen Daum

              #7
              Re: Please use error_reporting (E_ALL)

              Hi Matty!
              On Mon, 11 Aug 2003 01:33:57 +0000, matty
              <matt+nntp@askm enoquestions.co .uk> wrote:
              [color=blue]
              >André Næss wrote:
              >[color=green]
              >> matty:
              >>[color=darkred]
              >>> Maybe we need a FAQ...[/color]
              >>
              >> We certainly do, and the topic has been discussed before, but someone
              >> simply has to do it :/ A Wiki is maybe an even better idea as it makes it
              >> simple for many people to cooperatively develop it.
              >>
              >> André Næss[/color]
              >
              >
              >Don't know if I'd be prepared to do a Wiki - too many wiki terrorists around.
              >Maybe something with a confirmed email registration - I'll have a think. In
              >general, what would people want to see, beyond standard faq/wiki stuff?[/color]

              I think a FAQ would be more than enough. The FAQ of de.comp.lang.ph p.*
              is fabolous and contains not much more than FAQ.

              Jochen

              --
              Jochen Daum - CANS Ltd.
              PHP DB Edit Toolkit -- PHP scripts for building
              database editing interfaces.
              http://sourceforge.net/projects/phpdbedittk/

              Comment

              Working...