SitePoint Sponsor

User Tag List

Results 1 to 22 of 22
  1. #1
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    madness and strange errors

    everytime I code a script I get mysql errors caused by the queries...
    I'm debugging for like a half an hour, and then it works...and the code is EXACTLY the same as the one in the beginning

    like even this morning, first I had this:

    $query*= mysql_query("SELECT*userid*FROM*about*WHERE*name='$name' AND psw='$pass'");
    $num=mysql_num_rows($query);
    echo "$num";


    didn't work...so I go to the php site, I copy some code about mysql_num_rows, I change it a bit and I get this:

    $result = mysql_query("SELECT userid FROM about WHERE name='$name' AND psw='$pass'");
    $num_rows = mysql_num_rows($result);
    echo "$num_rows Rows\n";


    the only difference in my eyes are the variables names. Can anyone explain me why the second works and the first doesn't???I get strange things like this on EVERYthing I code with queries and I really would like to know what's wrong with the first one...
    I really don't get this, it's prolly a simpel mistake??

  2. #2
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The error could be at the lines before or after the codes you show us above. If possible, show us some codes and error message.

    John

  3. #3
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    <html>
        <head>
            <title>Sitemanager*</title>
            <link rel="stylesheet" type="text/css" href="styles.css">
        </head>

    <body bgcolor="c0c0c0"><center>

    <h2><b>RLG Sitemanager LOGIN</b></h2>

    <?php 
        
    function form()
        { 
    ?>
            <form method="post" action="<?php print("$PHP_SELF")?>">
            <table>
                <tr><td>Name</td><td><input type="text" name="name"></td></tr>
                <tr><td>Pass</td><td><input type="password" name="pass"></td></tr></table>
                <input type="submit" value="Submit">
            </form>
    <?php  }

        function 
    validate()
        {   global 
    $name$pass;  
            
    session_start();
            
            
    $result mysql_query("SELECT userid FROM about WHERE name='$name' AND psw=PASSWORD('$pass')");
            
    $num_rows mysql_num_rows($result); 
            if(
    $num_rows!=0)
            {    
    $clear*=*$name;
                
    session_register("clear");
                
    Header("Location:*/sitemanager.php");
            }
            else 
    Header("Location: /index.php");
        }
                    
            if(!
    $name||!$passform();
            if(
    $name&&$passvalidate();
               
    ?>
    *
    </center>
    </body>
    </html>
    the error is a parse error on this:
    PHP Code:
    {    $clear $name
    line

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does the parse error say? Are you sure you aren't getting a headers already sent error?

    ie
    Code:
    Warning: Cannot send session cookie - headers already sent by
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, but if I comment everything out that has to do with the sessions, it still gives the parse error

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php tries to give helpful error messages, what is it exactly? the line number is nice but not to be trusted alone. it saves much time to give the exact error message initially, requires less guessing and mind use.

    usually, including the line above and below and the exact error is enough to solve the mystery.

  7. #7
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, it just sais parse error, then the path of the file and then on line x
    that's all, these parse errors are never helpful...you can only guesse what you did wrong

    and there are NO lines below or above the error...

    the source code of the file with the error is just:
    PHP Code:
    <br>
    <
    b>Parse error</b>:  parse error in <b>/pathtosite.../manager/index.php</bon line <b>38</b><br

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    gives us the five lines before line 38 and the five lines after line 38 as well as line 38. It will be hard to tell you what your error is when you haven't told us what exact line the error falls on and showing us the code from that line as well as 5 -10 lines on each side of that line.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    euh.......if you check this post you will see that I already gave all the code.....

    PHP Code:
    {    $clear $name
    IS line 38, and you can see all the code around it.....

    ok, in my post it's line 30, but I didn't include the connection to the server...

    ow and if I put the "$clear = $name;" one line lower then it still gives a parse error on that line...
    and if you print the $num_rows then it GIVES a value, so I really don't understand why it gives an error...
    Last edited by =X=; Jul 4, 2001 at 13:37.

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So what you are saying is that you haven't changed the code at all since your first post? If you have it would be really helpful to see exactly what it is you are testing, not a derivetive of any changes you made to the original script.

    Also when does the parse error happen before or after pressing submit? There is obviously a parse error somewhere, but your code above does not show it. So could you kindly repaste your EXACT code that produces the error, form the start of the page to the end.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no I didn't change the code since the first post, since it works fine with the code I copied from the php site, and that one works fine (cfr. my first post). It seems stupid to keep going on about this then, but the fact is that I get these strange errors a lot, when there is no reason for them.

    The error -strangely- happens before pressing submit, so $pass and $name are NOT set, but he does execute validate()...
    So could you kindly repaste your EXACT code that produces the error, form the start of the page to the end.
    the code that is given is the exact code exept for the peace where I log into my database (and that conenction works, so that doesn't give the error...)

    do you see errors in that code?? I don't, and I think php is alive and teases me with strange errors

    UFE's: Unidentified F*****g Errors

  12. #12
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is that just because it says parse error on such and such a line, it is quite possible something above or below it actaully the culprit. So if you changed the query part, it might have something to do with it. Even if the query works there still can be a parse error somewhere in it. That is why I asked you to post the newest version of your script.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  13. #13
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah ok
    well, the only difference are these lines:
    PHP Code:
    $result mysql_query("SELECT userid FROM about WHERE name='$name' AND psw='$pass'"); 
    $num_rows mysql_num_rows($result); 
    echo 
    "$num_rows Rows\n"
    I just replaced the other with these, the rest of the script is the same...
    that's the main problem, these are +- the same lines, but these work and the other don't...

  14. #14
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I know why I get these errors....

    just found out...

    I prolly copied a small piece of that code from these forums.
    I had a strange parse error today again, with the code of freakysid
    I copied that and uploaded it but I got that UFE again.
    But then I noticed that my editor (editplus) didn't give the correct highlight to the words function, for,...

    so I went looking at the code of that forum page, and all spaces were nbsp !!!

    This was prolly a topic before...

    I would actually prefer the code to be inbetween <pre> tags and no color then with color but with nbsp, cuz then I always have to select the lenght of a space in my editor, and replace(all) with a REAL space...
    Last edited by =X=; Jul 5, 2001 at 04:41.

  15. #15
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by =X=
    PHP Code:
    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    <html>
        <head>
            <title>Sitemanager*</title>
            <link rel="stylesheet" type="text/css" href="styles.css">
        </head>

    <body bgcolor="c0c0c0"><center>

    <h2><b>RLG Sitemanager LOGIN</b></h2>

    <?php 
        
    function form()
        { 
    ?>
            <form method="post" action="<?php print("$PHP_SELF")?>">
            <table>
                <tr><td>Name</td><td><input type="text" name="name"></td></tr>
                <tr><td>Pass</td><td><input type="password" name="pass"></td></tr></table>
                <input type="submit" value="Submit">
            </form>
    <?php  }

        function 
    validate()
        {   global 
    $name$pass;  
            
    session_start();
            
            
    $result mysql_query("SELECT userid FROM about WHERE name='$name' AND psw=PASSWORD('$pass')");
            
    $num_rows mysql_num_rows($result); 
            if(
    $num_rows!=0)
            {    
    $clear*=*$name;
                
    session_register("clear");
                
    Header("Location:*/sitemanager.php");
            }
            else 
    Header("Location: /index.php");
        }
                    
            if(!
    $name||!$passform();
            if(
    $name&&$passvalidate();
               
    ?>
    *
    </center>
    </body>
    </html>
    This will not work without a mysql_connect function call right before the mysql_query call. (p.s. post #300!)

  16. #16
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes it does....it works if I replace all the non breaking spaces with normal spaces...

  17. #17
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by =X=
    yes it does....it works if I replace all the non breaking spaces with normal spaces...
    hm that's odd; the query should not work unless your host does something tricky and figured out a way to make every PHP file connect to the DB by default.

  18. #18
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    as I said before in this topic:
    ok, in my post it's line 30, but I didn't include the connection to the server...
    I do connect, but that's just not given in the code

  19. #19
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by =X=
    as I said before in this topic:
    I do connect, but that's just not given in the code
    OIC

    Too many things going 'round (plus haven't had my morning coffee yet ). Glad to hear it is all working though!

  20. #20
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heh thx
    hmm morning coffee ?
    either you live on the other side of the earth or you must have had a loooong night
    PHP-Webservices - Profesional Hosting and Programming of sites.

  21. #21
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by =X=
    heh thx
    hmm morning coffee ?
    either you live on the other side of the earth or you must have had a loooong night
    Columbus, OH (USA!). So it's 10AM here but we had a website launch today (I work for Victoria's Secret Catalogue on the web team! www.victoriassecret.com) so everyone's a bit pumped. I'm tired since I took the week off -- 5 days of getting up at 11AM really really removes the desire to wake up for work at 8AM!

  22. #22
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    turn this :
    $num_rows = mysql_num_rows($result);

    into :
    $num_rows = mysql_num_rows($result);
    echo mysql_error();

    try mysql_error() at a few places, it can be helpful.


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
  •