What is best to find errors in php coding

Discussion in 'PHP' started by shaz_again, Dec 14, 2007.

  1. #1
    Hi Pros,
    i m trying to lear php, i used txt editor & now i m using Drwamweaver but still unable to point out my mistakes.
    i have to read it again & again to find problem is there any other easy way to find out the problem.
    here is one example i tried but getting this error massage

    and here is coding

     
    shaz_again, Dec 14, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    -Reading (and understanding) the error message. It even tells you the approximate line number.
    -Knowing the basic syntax.
    -A syntax highlighter (like dreamweaver)
    -If no error comes up, set this at the top of your script:
    
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    PHP:
    EDIT:

    Your error says that there's probably a curly bracket missing }. The number always needs to be even. If it's odd, then you know you missed one somewhere.
     
    nico_swd, Dec 14, 2007 IP
  3. shaz_again

    shaz_again Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah bro it mention the line but u can see its saying 49 where "</html> written.

    i checked there is total 6 { }. no one is missing :(

    but still its very difficult to find error by this way :(

    thanks alot for your help
     
    shaz_again, Dec 14, 2007 IP
  4. shaz_again

    shaz_again Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    any other solution, plz i m getting out of this.
     
    shaz_again, Dec 14, 2007 IP
  5. ndreamer

    ndreamer Guest

    Messages:
    339
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #5
    test your code regularly in small blocks, so if you do get an error you can track it down fairly easy. the line number reported for endings is nearly always wrong, you have to backtrack from that line number thats given until you find the error.
     
    ndreamer, Dec 14, 2007 IP
  6. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I tried your code and couldn't reproduce the error. At what point are you getting the error? Before entering any data or as soon as you open the page?
     
    Gawk, Dec 14, 2007 IP
  7. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hows that?
     
    MMJ, Dec 14, 2007 IP
  8. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Next time, you might want to index your codes. It will make your codes easier to debug.
     
    vonvhen, Dec 14, 2007 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    Every bracket you open needs to be closed. So it's always a pair of 2. = Always even. :)
     
    nico_swd, Dec 14, 2007 IP
  10. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Try changing

    <?
    }
    ?>
    Code (markup):
    to
    <?php
    }
    ?>
    Code (markup):
    at the very end.


    There really is no easy way to debug code. As you gain experience you'll learn to more quickly pick out the simple mistakes. If you use a syntax highlighter you will gain an appreciation for which bits of your code should be which colour but it takes time.
     
    streety, Dec 14, 2007 IP
  11. sunnyverma1984

    sunnyverma1984 Well-Known Member

    Messages:
    342
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    120
    #11
    your script is OK its working fine on my wampserver no error
     
    sunnyverma1984, Dec 14, 2007 IP
  12. shaz_again

    shaz_again Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Thank you very much for your responce.
    Streety you got it. as i wrote php it started working
    by the way i m also using WAMP server
    Thank you everybody, now i m using PHP Designer 2008 & its very helping ;)
     
    shaz_again, Dec 15, 2007 IP
  13. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #13
    
    if($x ==  z){
    echo "{";
    }
    
    PHP:
    Odd :p

    You are right. To avoid such problem, you can practice writing the code without {} but would make it hard to understand later on.

    Peace,
     
    Barti1987, Dec 15, 2007 IP
  14. mudassarahmad

    mudassarahmad Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    <html>
    <head><title>Untitled Document</title></head>
    <body>
    <?php
    if (isset($_POST[posted])) {
    echo "<form method='POST' action='dynamic1.php'>";
    for ($counter = 0; $counter < $_POST[number]; $counter ++)
    {
    $offset = $counter + 1;
    echo "<br>PLease enter the name of child number $offset<br>";
    echo "<input name='child[]' type='text'>";
    }
    echo "<br>Press the button to moe on<br>";
    echo "<input type='submit' value='Next'>";
    echo"<input type='hidden' name='posted01' value='true'></form>";

    } else {

    if (isset($_POST[posted01])) {
    $count=0;
    echo "Your childrens names are: ";
    do
    {
    $childs_names = $_POST[child][$count];
    echo"<br><b>$childs_names</b>";
    $checkempty = $childs_names;
    $count = $count + 1;
    } while ($checkempty != "");
    if ($count == 1) {
    echo "Not applicable";
    }
    }

    ?>
    <hr>
    <form method="POST" action="dynamic1.php">
    <input type="hidden" name="posted" value="true">
    How many children do u have?
    <input type="text" name="number">
    <br>
    <br>
    <input type="submit" value="Submit Number">
    <br>
    </form>
    <?php
    }
    ?>
    </body>
    </html>
     
    mudassarahmad, Dec 15, 2007 IP
  15. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Sorry, but I really don't follow. :eek:
     
    MMJ, Dec 15, 2007 IP
  16. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #16
    use a php editor

    or dreamweaver

    they help a lot

    Regards

    Alex
     
    kmap, Dec 15, 2007 IP
  17. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #17
    Do you know how to code in PHP?

    If you open curly brackets { for if or while/for loop statements than you must have to close curly brackets }

    What's difficult in it?:confused:
     
    greatlogix, Dec 16, 2007 IP
  18. shaz_again

    shaz_again Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    you buddies but here the problem was not curly brackets.

    i just missed writing "php" in that line

    <?php
    }
    ?>

    no everything is perfectly fine
     
    shaz_again, Dec 16, 2007 IP
  19. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #19
    But why does the line number odd when you miss one?
     
    MMJ, Dec 16, 2007 IP
  20. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Nobody is saying the line number is odd. If you go through all the code counting up the brackets the number you arrive at will be odd.
     
    streety, Dec 17, 2007 IP