php login script

Discussion in 'PHP' started by solarthur01@hotmail.com, Sep 28, 2007.

?

php login

  1. php

    2 vote(s)
    50.0%
  2. php

    2 vote(s)
    50.0%
  1. #1
    Can any of you geniuses help...
    im getting this error and cant think of a reason:

    Parse error: syntax error, unexpected $end in C:\Documents and Settings\Sol\My Documents\php\xampplite\htdocs\login3\register.php on line 50

    heres the code:

    <?php
    // Connects to your Database
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("login2") or die(mysql_error());


    //This code runs if the form has been submitted
    if (isset($_POST['submit'])) {

    //This makes sure they did not leave any fields blank
    if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
    die('You did not complete all of the required fields');
    }

    // checks if the username is in use
    if (!get_magic_quotes_gpc()) {
    $_POST['username'] = addslashes($_POST['username']);
    }
    $usercheck = $_POST['username'];
    $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
    or die(mysql_error());
    $check2 = mysql_num_rows($check);

    //if the name exists it gives an error
    if ($check2 != 0) {
    die('Sorry, the username '.$_POST['username'].' is already in use.');
    }

    // this makes sure both passwords entered match
    if ($_POST['pass'] != $_POST['pass2']) {
    die('Your passwords did not match.');
    }

    // here we encrypt the password and add slashes if needed
    $_POST['pass'] = md5($_POST['pass']);
    if (!get_magic_quotes_gpc()) {
    $_POST['pass'] = addslashes($_POST['pass']);
    $_POST['username'] = addslashes($_POST['username']);
    }

    // now we insert it into the database
    $insert = "INSERT INTO users (username, password)
    VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
    $add_member = mysql_query($insert);
    ?>


    <h1>Registered</h1>
    <p>Thank you, you have registered - you may now login</a>.</p>

    some one please help!!!!!!

    cheers guys!!
     
    solarthur01@hotmail.com, Sep 28, 2007 IP
  2. andrew1810

    andrew1810 Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    <?php
    // Connects to your Database
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("login2") or die(mysql_error());
    
    
    //This code runs if the form has been submitted
    if (isset($_POST['submit'])) {
    
    //This makes sure they did not leave any fields blank
    if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
    die('You did not complete all of the required fields');
    }
    
    // checks if the username is in use
    if (!get_magic_quotes_gpc()) {
    $_POST['username'] = addslashes($_POST['username']);
    }
    $usercheck = $_POST['username'];
    $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
    or die(mysql_error());
    $check2 = mysql_num_rows($check);
    
    //if the name exists it gives an error
    if ($check2 != 0) {
    die('Sorry, the username '.$_POST['username'].' is already in use.');
    }
    
    // this makes sure both passwords entered match
    if ($_POST['pass'] != $_POST['pass2']) {
    die('Your passwords did not match.');
    }
    
    // here we encrypt the password and add slashes if needed
    $_POST['pass'] = md5($_POST['pass']);
    if (!get_magic_quotes_gpc()) {
    $_POST['pass'] = addslashes($_POST['pass']);
    $_POST['username'] = addslashes($_POST['username']);
    }
    
    // now we insert it into the database
    $insert = "INSERT INTO users (username, password)
    VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
    $add_member = mysql_query($insert);
    }
    ?>
    
    
    <h1>Registered</h1>
    <p>Thank you, you have registered - you may now login</a>.</p>
    PHP:
     
    andrew1810, Sep 28, 2007 IP
    nico_swd likes this.
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    Hold on there, I still didn't decide for which poll option to vote. :D
     
    nico_swd, Sep 28, 2007 IP
  4. solarthur01@hotmail.com

    solarthur01@hotmail.com Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    that didnt do the trick
     
    solarthur01@hotmail.com, Sep 28, 2007 IP
  5. andrew1810

    andrew1810 Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm not getting any syntax errors on the script, what error are you getting?
     
    andrew1810, Sep 28, 2007 IP
  6. solarthur01@hotmail.com

    solarthur01@hotmail.com Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Parse error: syntax error, unexpected $end in C:\Documents and Settings\Sol\My Documents\php\xampplite\htdocs\login3\register.php on line 50

    unexpected end
     
    solarthur01@hotmail.com, Sep 28, 2007 IP
  7. andrew1810

    andrew1810 Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Have you got the
    }
    PHP:
    at the very end of the script before the
    ?>
    PHP:
    ?
     
    andrew1810, Sep 28, 2007 IP
  8. solarthur01@hotmail.com

    solarthur01@hotmail.com Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    its meant to tell you if the passwords dont match it just says :

    Table 'login2.users' doesn't exist
     
    solarthur01@hotmail.com, Sep 28, 2007 IP
  9. andrew1810

    andrew1810 Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You don't have a table called users in the login2 database, you'll need to create that or alter the code to the correct table/db name
     
    andrew1810, Sep 28, 2007 IP
  10. solarthur01@hotmail.com

    solarthur01@hotmail.com Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    thanks a million mate gt a few more problems i might have!!
    u r a star
     
    solarthur01@hotmail.com, Sep 28, 2007 IP
  11. solarthur01@hotmail.com

    solarthur01@hotmail.com Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    hi guys its me again, When i run the below i have the following error: Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\Sol\My Documents\php\xampplite\htdocs\site.php:6) in C:\Documents and Settings\Sol\My Documents\php\xampplite\htdocs\site.php on line 66

    can anyone help
     
    solarthur01@hotmail.com, Sep 29, 2007 IP
  12. solarthur01@hotmail.com

    solarthur01@hotmail.com Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    btw heres the code lol:
    <html>
    <head>
    <title>Order Book System</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" href="css/styles.css" type="text/css">
    <style type="text/css">
    <!--
    .style1 {color: #408080}
    .style3 {color: #00FFFF}
    .style10 {color: #CC0000}
    -->
    </style>
    </head>

    <body>
    <table width="775" border="0" align="center" cellpadding="0" cellspacing="0" height="140">
    <tr>
    <td background="images/image1.jpg" class="logo style1" style="padding-left:30px"><p><img src="images/m3.jpg" width="151" height="111"><span class="style3">OrderBook Training</span></p></td>
    </tr>
    </table>
    <table width="775" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td bgcolor="#BFE1E7" width="200" valign="top" align="center"> <br>
    <table width="150" border="0" align="center" cellpadding="3" cellspacing="3" class="text">
    <tr>
    <td><b><a href="#">About Us</a></b></td>
    </tr>
    <tr>
    <td><b><a href="#">Services</a></b></td>
    </tr>
    <tr>
    <td><b><a href="#">Products</a></b></td>
    </tr>
    <tr>
    <td><b><a href="#">Downloads</a></b></td>
    </tr>
    <tr>
    <td><b><a href="#">Contact Us</a></b></td>
    </tr>
    </table>
    <p>



    <?php
    // Connects to your Database
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("login2") or die(mysql_error());


    //Checks if there is a login cookie
    if(isset($_COOKIE['ID_my_site']))

    //if there is, it logs you in and directes you to the members page
    {
    $username = $_COOKIE['ID_my_site'];
    $pass = $_COOKIE['Key_my_site'];
    $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
    while($info = mysql_fetch_array( $check ))
    {
    if ($pass != $info['password'])
    {
    }
    else
    {
    header("Location: members.php");

    }
    }
    }

    //if the login form is submitted
    if (isset($_POST['submit'])) { // if form has been submitted

    // makes sure they filled it in
    if(!$_POST['username'] | !$_POST['pass']) {
    //header("Location: members.php");
    die('You did not fill in a required fieldxczxczxczxc.');
    }
    // checks it against the database

    if (!get_magic_quotes_gpc()) {
    $_POST['email'] = addslashes($_POST['email']);
    }
    $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());

    //Gives error if user dosen't exist
    $check2 = mysql_num_rows($check);
    if ($check2 == 0) {
    die('That user does not exist in our database.<a href=add.php>Click Here to Register</a>');
    }
    while($info = mysql_fetch_array( $check ))
    {
    $_POST['pass'] = stripslashes($_POST['pass']);
    $info['password'] = stripslashes($info['password']);
    $_POST['pass'] = md5($_POST['pass']);

    //gives error if the password is wrong
    if ($_POST['pass'] != $info['password']) {
    die('Incorrect password, please try again.');
    }
    else
    {

    // if login is ok then we add a cookie
    $_POST['username'] = stripslashes($_POST['username']);
    $hour = time() + 3600;
    setcookie(ID_my_site, $_POST['username'], $hour);
    setcookie(Key_my_site, $_POST['pass'], $hour);

    //then redirect them to the members area
    header("Location: members.php");
    }
    }
    }
    else
    {

    // if they are not logged in
    ?>
    <form name="form2" method="post" action="login.php">
    <table border="0">
    <tr><td colspan=2><h1>Login</h1></td></tr>
    <tr><td>Username:</td><td>
    <input type="text" name="username" maxlength="40">
    </td></tr>
    <tr><td>Password:</td><td>
    <input type="password" name="pass" maxlength="50">
    </td></tr>
    <tr><td colspan="2" align="right">
    <input type="submit" name="submit" value="Login">
    </td></tr>
    </table>
    </form>
    <?php
    }

    ?>
    &nbsp;</p>
    <p>&nbsp;</p></td>
    <td style="padding-left:25px; padding-right:25px; padding-top:25px; padding-bottom:25px" class="text" bgcolor="#FFFFFF"><span class="title">Welcome To Online Order Book Training</span>
    <p>OrderBook is a training service that provides students with notes and online quizes. Orderbook also enables you to study at your own pace and also in the comfort of your home. Signing up to orderbook plus will enable you to have a tutor who will guide you through the course and set up appointments to discuss your progress. Please click sign in (existing users) or register to register (new users) </p>

    <p><br>
    <a href="http://www.lunarpages.com/?id=webdotcom&campaign=tytempls" target="_blank"></a> </p> </td>
    </tr>
    <tr>
    <td bgcolor="#BFE1E7" valign="top" align="center">&nbsp;</td>
    <td style="padding-left:25px; padding-right:25px; padding-top:25px; padding-bottom:25px" class="text" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    </table>
    <table width="775" border="0" align="center" cellpadding="0" cellspacing="0" height="30">
    <tr>
    <td class="text" align="center" bgcolor="#D0ECF1">Designed by Solomon Arthur. All rights reserved. </td>
    </tr>
    </table>
    </body>
    </html>
     
    solarthur01@hotmail.com, Sep 29, 2007 IP
  13. wvccboy

    wvccboy Notable Member

    Messages:
    2,632
    Likes Received:
    81
    Best Answers:
    1
    Trophy Points:
    250
    #13
    ^^ Is that all supposed to be on one page?

    Or am I missing the point :p
     
    wvccboy, Oct 1, 2007 IP
  14. kendo1979

    kendo1979 Peon

    Messages:
    208
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    tooo much } in

    header("Location: members.php");
    }
    }
    }
     
    kendo1979, Oct 2, 2007 IP
  15. scriptman

    scriptman Peon

    Messages:
    175
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #15
    You should really spend the few seconds it takes to comprehend the errors yourself, or you will never learn. I don't think the problem is with brackets or the script would bunk out without any processing.

    The issue is you are trying to do a header redirect but you have already output headers (Due to the HTML at the top of the page). You need to bring your PHP up above the html to do the processing before output. I am not going to post a cut-and-paste solution because if you can fix it yourself, then you will have learned something ;)

    Also you should probably exit(); after the header();
     
    scriptman, Oct 3, 2007 IP