Results 1 to 25 of 25

Thread: Mysql table error?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Mysql table error?

    Hi Everyone!
    I created a register script that works fine, and creates the correct fields and stuff in the database, but when I go to login, it comes with an error...

    The error says:
    Parse error: parse error, unexpected $ in /home/public_html/logscript.php on line 61

    The error comes up on the logscript.php file (which is linked by a html form (<form action="logscript.php" method="post">...) on a file called login.php)

    Here is the code on logscript.php
    Code:
    <?php
    
    include("config.php"); 
    
    // connect to the mysql server
    $link = mysql_connect($server, $db_user, $db_pass)
    or die ("Could not connect to mysql because ".mysql_error());
    
    // select the database
    mysql_select_db($database)
    or die ("Could not select database because ".mysql_error());
    
    $match = "select id from $table where username = '".$_POST['username']."'
    and password = '".$_POST['password']."';"; 
    
    $qry = mysql_query($match)
    or die ("Could not match data because ".mysql_error());
    $num_rows = mysql_num_rows($qry); 
    
    if ($num_rows <= 0) { 
    echo "Sorry, there is no username $username with the specified password.<br>";
    echo "<a href=login.php>Try again</a>";
    exit; 
    } else {
    
    setcookie("loggedin", "TRUE", time()+(3600 * 24));
    setcookie("mysite_username", "$username");
    
    if ($class != One) {
    echo "You are now logged in as One!<br>"; 
    echo "Continue to the <a href=one/index.php>members</a> section.";
    
    if ($class != Two) {
    echo "You are now logged in as Two!<br>"; 
    echo "Continue to the <a href=two/index.php>members</a> section.";
    
    if ($class != Three) {
    echo "You are now logged in as Three!<br>"; 
    echo "Continue to the <a href=three/index.php>members</a> section.";
    
    if ($class != Four) {
    echo "You are now logged in as Four!<br>"; 
    echo "Continue to the <a href=Four/index.php>members</a> section.";
    
    if ($class != Five) {
    echo "You are now logged in as Five!<br>"; 
    echo "Continue to the <a href=Five/index.php>members</a> section.";
    
    if ($class != Six) {
    echo "You are now logged in as Six!<br>"; 
    echo "Continue to the <a href=Six/index.php>members</a> section.";
    
    if ($class != Seven) {
    echo "You are now logged in as Seven!<br>"; 
    echo "Continue to the <a href=Seven/index.php>members</a> section.";
    
    if ($class != Eight) {
    echo "You are now logged in as Eight!<br>"; 
    echo "Continue to the <a href=Eight/index.php>members</a> section.";
    
    ?>
    Also, the "class" ($class) is found in different ROWS in the user table... I created a test user, called "test" and the class is "One".

    Thanks to anyone who takes the time to read my problem and to all who try to help!
    Last edited by drkelusion; Aug 21st, 2005 at 07:53 AM.

  2. #2
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: Mysql table error?

    You missed your closing '}' on most of your if statments, there should be a corresponding closing '}' for every opened '{'. Also, you need to quote your 'One', 'Two' ect...
    Code:
    if ($class != 'One') {
    echo "You are now logged in as One!<br>"; 
    // you shoud have double quotes in your html, so you could do it like this to make it easier..
    echo 'Continue to the <a href="one/index.php">members</a> section.';
    }
    
    // same for the rest of them...
    {yak}

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Re: Mysql table error?

    Hi!
    Thankyou for helping!
    I'm now getting this error when I editted the script:

    Parse error: parse error, unexpected $ in /home/public_html/logscript.php on line 68

    Thanks again for trying to help!
    Last edited by drkelusion; Aug 21st, 2005 at 05:35 PM.

  4. #4
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Mysql table error?

    check and make sure that u didnt accidently make something a string on that line or add a $ on accident

  5. #5
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Mysql table error?

    ur script doesnt have 68 lines lol we'll at least the example u sent doesnt

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Re: Mysql table error?

    Here's the new editted code:

    Code:
    <?php
    
    include("config.php"); 
    
    // connect to the mysql server
    $link = mysql_connect($server, $db_user, $db_pass)
    or die ("Could not connect to mysql because ".mysql_error());
    
    // select the database
    mysql_select_db($database)
    or die ("Could not select database because ".mysql_error());
    
    $match = "select id from $table where username = '".$_POST['username']."'
    and password = '".$_POST['password']."';"; 
    
    $qry = mysql_query($match)
    or die ("Could not match data because ".mysql_error());
    $num_rows = mysql_num_rows($qry); 
    
    if ($num_rows <= 0) { 
    echo "Sorry, there is no username $username with the specified password.<br>";
    echo "<a href=login.php>Try again</a>";
    exit; 
    } else {
    
    setcookie("loggedin", "TRUE", time()+(3600 * 24));
    setcookie("mysite_username", "$username");
    
    if ($class != 'One') {
    echo "You are now logged in as an One!<br>"; 
    echo 'Continue to the <a href="One/index.php">members</a> section.';
    }
    
    if ($class != 'Two') {
    echo "You are now logged in as an Two!<br>"; 
    echo 'Continue to the <a href="Two/index.php">members</a> section.';
    }
    
    if ($class != 'Three') {
    echo "You are now logged in as a Three!<br>"; 
    echo 'Continue to the <a href="Three/index.php">members</a> section.';
    }
    
    if ($class != 'Four') {
    echo "You are now logged in as a Four!<br>"; 
    echo 'Continue to the <a href="Four/index.php">members</a> section.';
    }
    
    if ($class != 'Five') {
    echo "You are now logged in as a Five!<br>"; 
    echo 'Continue to the <a href="Five/index.php">members</a> section.';
    }
    
    if ($class != 'Six') {
    echo "You are now logged in as an Six!<br>"; 
    echo 'Continue to the <a href="Six/index.php">members</a> section.';
    }
    
    if ($class != 'Seven') {
    echo "You are now logged in as a Seven!<br>"; 
    echo 'Continue to the <a href="Seven/index.php">members</a> section.';
    }
    
    if ($class != 'Eight') {
    echo "You are now logged in as Eight!<br>"; 
    echo 'Continue to the <a href="Eight/index.php">members</a> section.';
    }
    ?>
    Did I do something wrong?
    By the way, just to let you know, the "$class" is there because I want the code to check which "Class" the member is in (Which the information is found in "Users" table, in rows), which is found in the 6th column of every row for every user.

    There is no "$class = [something]" code in there, am I doing something completely wrong?

    Thanks again for helping...

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Re: Mysql table error?

    Quote Originally Posted by ninjanutz
    ur script doesnt have 68 lines lol we'll at least the example u sent doesnt
    Lol.. I know, that's something I'm confused about too..
    It's the full File, I didnt edit anything when I copied it to here..

  8. #8
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: Mysql table error?

    You're getting closer, this time you missed the closing '}' of your else statement:
    Code:
    <?php
    
    include("config.php"); 
    
    // connect to the mysql server
    $link = mysql_connect($server, $db_user, $db_pass)
    or die ("Could not connect to mysql because ".mysql_error());
    
    // select the database
    mysql_select_db($database)
    or die ("Could not select database because ".mysql_error());
    
    $match = "select id from $table where username = '".$_POST['username']."'
    and password = '".$_POST['password']."';"; 
    
    $qry = mysql_query($match)
    or die ("Could not match data because ".mysql_error());
    $num_rows = mysql_num_rows($qry); 
    
    if ($num_rows <= 0) { 
    echo "Sorry, there is no username $username with the specified password.<br>";
    echo "<a href=login.php>Try again</a>";
    exit; 
    } else {
    
    setcookie("loggedin", "TRUE", time()+(3600 * 24));
    setcookie("mysite_username", "$username");
    
    if ($class != 'One') {
    echo "You are now logged in as an One!<br>"; 
    echo 'Continue to the <a href="One/index.php">members</a> section.';
    }
    
    if ($class != 'Two') {
    echo "You are now logged in as an Two!<br>"; 
    echo 'Continue to the <a href="Two/index.php">members</a> section.';
    }
    
    if ($class != 'Three') {
    echo "You are now logged in as a Three!<br>"; 
    echo 'Continue to the <a href="Three/index.php">members</a> section.';
    }
    
    if ($class != 'Four') {
    echo "You are now logged in as a Four!<br>"; 
    echo 'Continue to the <a href="Four/index.php">members</a> section.';
    }
    
    if ($class != 'Five') {
    echo "You are now logged in as a Five!<br>"; 
    echo 'Continue to the <a href="Five/index.php">members</a> section.';
    }
    
    if ($class != 'Six') {
    echo "You are now logged in as an Six!<br>"; 
    echo 'Continue to the <a href="Six/index.php">members</a> section.';
    }
    
    if ($class != 'Seven') {
    echo "You are now logged in as a Seven!<br>"; 
    echo 'Continue to the <a href="Seven/index.php">members</a> section.';
    }
    
    if ($class != 'Eight') {
    echo "You are now logged in as Eight!<br>"; 
    echo 'Continue to the <a href="Eight/index.php">members</a> section.';
    }
    }
    ?>
    I'm not really following you on the $class issue, although looking at your code,
    PHP Code:
    if ($class != 'One') {
    echo 
    "You are now logged in as an One!<br>"
    echo 
    'Continue to the <a href="One/index.php">members</a> section.';

    You're saying, if $class is not equal to 'One' then echo you are now logged in as 'One', which doesn't really make much sense, I'm thinking you meant it to be:
    PHP Code:
    if ($class == 'One') {
    echo 
    "You are now logged in as an One!<br>"
    echo 
    'Continue to the <a href="One/index.php">members</a> section.';

    BTW:
    When you get the 'Parse error: parse error, unexpected $ in ... on line...' errors, it usually means you missed a curly brace somewhere.
    {yak}

  9. #9
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Mysql table error?

    thats wut i was gunna say... i noticed thatas soon as i read the code. looks usefull.. tho.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Re: Mysql table error?

    Omg, thankyou so much {yak} and PlaGuE, who was about to post the answer...
    Also, thankyou ninjanutz for helping earlier.

    Okay, so I now know that the script works, however, Other than the page coming up with:
    You are now logged in as an One!
    Continue to the members section.

    For some reason, it doesnt come up with anything (just a blank page)
    Any ideas?

    Thanks again for everyone who helped!!

  11. #11
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Mysql table error?

    wut do you mean.. blank page.. ...

    from wut i read... it looks likes its just supposed to show..
    You are now logged in as an One!
    Continue to the members section.(<---link to page---<<)

    if i miss read any part.. plz tell me... so i can get a better understanding to help you.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Re: Mysql table error?

    No, you read correctly, but for some reason it doesnt show You are now logged in as an One!
    Continue to the members section.
    at all..
    It's just blank page (nothing is there). The file is called logscript.php still, but all it is is just a blank html page:
    <html><body></body></html> is the only thing shown in the Source file.

  13. #13
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Mysql table error?

    hmm...would i be able to see the page... so that i can visualise...

    it looks like teh problem is in here

    PHP Code:
    include("config.php");

    // connect to the mysql server
    $link mysql_connect($server$db_user$db_pass)
    or die (
    "Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die (
    "Could not select database because ".mysql_error());

    $match "select id from $table where username = '".$_POST['username']."'
    and password = '"
    .$_POST['password']."';";

    $qry mysql_query($match)
    or die (
    "Could not match data because ".mysql_error());
    $num_rows mysql_num_rows($qry);

    if (
    $num_rows <= 0) {
    echo 
    "Sorry, there is no username $username with the specified password.<br>";
    echo 
    "<a href=login.php>Try again</a>";
    exit;
    } else {

    setcookie("loggedin""TRUE"time()+(3600 24));
    setcookie("mysite_username""$username"); 
    but i wont know... until i can see it not showing...

    I tried it myself.. and it displays stuff... but its just it cant find anything... even tho theres stuff there..lol... so im at a loss
    Last edited by PlaGuE; Aug 22nd, 2005 at 04:00 AM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Re: Mysql table error?

    Sure, the link to the login page is at:
    http://www.animefusion.net/RPG/testing/login.php

    Just use:
    Username: Testing
    Password: password

    I did, however, edit the code and replaced "($class != 'One')" to the appropriate class to fit the signup page (eg. "One" is actually "Elements")

    The account above is set to Class "Six", which is "Archer" in the editted script.
    Thanks again for trying to help!

  15. #15
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Mysql table error?

    try making $num_rows == 0... if that dont work.. take out the exit... lol.. and if that dont work.. change both..lol...

    I must be missing sumtin... cuz it should work.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Re: Mysql table error?

    ... I tried removing "exit", and editting "<=", and then even tried changing/removing both, but it still seems to come up with a blank page...

    Code:
    $qry = mysql_query($match)
    or die ("Could not match data because ".mysql_error());
    $num_rows = mysql_num_rows($qry); 
    
    if ($num_rows == 0) { 
    echo "Sorry, there is no username $username with the specified password.<br>";
    echo "<a href=login.php>Try again</a>";
    } else {
    
    setcookie("loggedin", "TRUE", time()+(3600 * 24));
    setcookie("mysite_username", "$username");
    I removed "exit;" and changed "<=" to "==" and neither worked at all
    Thankyou for helping though.. Maybe you know what else I may have done wrong?

  17. #17
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Mysql table error?

    to be honest... i have no clue why its not working...
    hopefully one of the others know... hmm... very wierd... cuz from the code.. it should work...

    ----------------------------
    oohh... i just thought of sumtin... is the $class variable being passed or globalized in the script... cuz maybe, this is just a thought, its not being picked up.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Re: Mysql table error?

    Oh, okay..
    Hopefully someone knows..
    Thanks again for trying to help

  19. #19
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: Mysql table error?

    I believe your problem lies here:
    Code:
    $qry = mysql_query($match)
    Missed a semi colon:
    Code:
    $qry = mysql_query($match);
    Good luck
    {yak}

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Re: Mysql table error?

    I seem to get this error now
    Parse error: parse error, unexpected T_LOGICAL_OR in /home/hanime07/public_html/RPG/testing/logscript.php on line 17

    Code:
    <?php
    
    include("config.php"); 
    
    // connect to the mysql server
    $link = mysql_connect($server, $db_user, $db_pass)
    or die ("Could not connect to mysql because ".mysql_error());
    
    // select the database
    mysql_select_db($database)
    or die ("Could not select database because ".mysql_error());
    
    $match = "select id from $table where username = '".$_POST['username']."'
    and password = '".$_POST['password']."';"; 
    
    $qry = mysql_query($match);
    or die ("Could not match data because ".mysql_error());
    $num_rows = mysql_num_rows($qry); 
    
    if ($num_rows <= 0) { 
    echo "Sorry, there is no username $username with the specified password.<br>";
    echo "<a href=login.php>Try again</a>";
    exit;
    } else
    Something to do with or die ("Could not match data because ".mysql_error()); I assume?

    Thanks yet again for helping!

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Re: Mysql table error?

    Hi Again!
    As posted above, I thought the error would be in "or die ("Could not match data because ".mysql_error());" so I deleted that line, and it seems that now it just goes to a blank page, like it did earlier..

    Any ideas would be greatly appreciated!
    Thankyou again

  22. #22
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Mysql table error?

    You are making a variable assignment before using a logical or, you need to enclose the variable assignment in brackets:
    PHP Code:
    // connect to the mysql server
    ($link mysql_connect($server$db_user$db_pass))
    or die (
    "Could not connect to mysql because ".mysql_error()); 
    It is however, better coding practice to use an IF statement instead of or die(). It makes the code easier to follow:
    PHP Code:
    // connect to the mysql server
    if (! ($link mysql_connect($server$db_user$db_pass))) {
        die (
    "Could not connect to mysql because ".mysql_error());

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    28

    Re: Mysql table error?

    Hi! I changed what you included, but seem to be getitng nearly the exact same problem;
    Parse error: parse error, unexpected T_LOGICAL_OR in /home/hanime07/public_html/RPG/testing/logscript.php on line 18

    Thankyou for helping btw!!

  24. #24
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Mysql table error?

    The code above it correct and won't produce a parse error. Try copying and pasting the code above. Which version of PHP are you using?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  25. #25
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Mysql table error?

    I've justl looked at your code again. It isn't that line which is causing the error, it is line 18, which is here:
    Code:
    $qry = mysql_query($match);
    or die ("Could not match data because ".mysql_error());
    $num_rows = mysql_num_rows($qry);
    When you get an error like that, PHP will give you information about the line number and the file in which it occured, this can be very useful
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width