Unexpected $end :/

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hey
Forum Newbie
Posts: 2
Joined: Wed Mar 25, 2009 10:54 pm

Unexpected $end :/

Post by Hey »

Code: Select all

<?php
 
// simple login script
 
// filename: login.php
 
   $form = '
       Simple Login Form<br>
 
       <form action=”login.php” method=”post”>
 
       <input type=”text” name=”username”>
 
       <input type=”password” name=”password”>
 
       <input type=”submit” name=”submit” value=”submit this”>
 
       </form>
 
       ';
 
if(isset($_POST['submit'])){
 
    $hm = authenticate($_POST['username'], $_POST['password']);
 
    $hm2 = mysql_num_rows($hm);
 
    if($hm2 > 0){
 
      echo 'wat';
 
    }else{
 
      echo 'username / password not valid<br>';
 
      echo $form;
 
    }
 
}else{
 
    echo $form;
 
}
 
function authenticate($user, $pass){
 
    $user = str_replace(' ', '', $user); //remove spaces
 
    $pass = str_replace(' ', '', $pass); //remove spaces
 
    $user = str_replace('%20&#8243', '', $user); //remove escaped spaces
 
    $pass = str_replace('%20&#8243', '', $pass); //remove escaped spaces
 
    // add slashes to escape things like quotes and apostrophes
 
    // because they can be used to hijack SQL statements!
 
    $user = addslashes($user); //remove spaces from username
 
    $pass = addslashes($pass); //remove spaces from password
 
    // the function md5 creates a unique 32 character string,
 
    $pass = md5($pass);
 
    $request = 'SELECT * FROM users WHERE password=’$pass’ AND email="$user"';
 
    // Pass the request to the mysql connection,
 
    $results = query_db($request);
 
    // if mysql returns any number of rows great than 0 there is a match
 
    return $results;
function query_db($query)
{
include("config.php");
}
[b][u]?>[/b][/u]
I get unexpected $end in line 81
Line 81 is bolded and underlined
sujithtomy
Forum Commoner
Posts: 46
Joined: Tue Mar 24, 2009 4:43 am

Re: Unexpected $end :/

Post by sujithtomy »

Hello Hay,

You havent closed the "}" tag for function authenticate.

Here is the corrected code.....

Code: Select all

 
<?php
 
// simple login script
 
// filename: login.php
 
   $form = '
       Simple Login Form<br>
 
       <form action=”login.php” method=”post”>
 
       <input type=”text” name=”username”>
 
       <input type=”password” name=”password”>
 
       <input type=”submit” name=”submit” value=”submit this”>
 
       </form>
 
       ';
 
if(isset($_POST['submit'])){
 
    $hm = authenticate($_POST['username'], $_POST['password']);
 
    $hm2 = mysql_num_rows($hm);
 
    if($hm2 > 0){
 
      echo 'wat';
 
    }else{
 
      echo 'username / password not valid<br>';
 
      echo $form;
 
    }
 
}else{
 
    echo $form;
 
}
 
function authenticate($user, $pass){
 
    $user = str_replace(' ', '', $user); //remove spaces
 
    $pass = str_replace(' ', '', $pass); //remove spaces
 
    $user = str_replace('%20&#8243', '', $user); //remove escaped spaces
 
    $pass = str_replace('%20&#8243', '', $pass); //remove escaped spaces
 
    // add slashes to escape things like quotes and apostrophes
 
    // because they can be used to hijack SQL statements!
 
    $user = addslashes($user); //remove spaces from username
 
    $pass = addslashes($pass); //remove spaces from password
 
    // the function md5 creates a unique 32 character string,
 
    $pass = md5($pass);
 
    $request = 'SELECT * FROM users WHERE password=’$pass’ AND email="$user"';
 
    // Pass the request to the mysql connection,
 
    $results = query_db($request);
 
    // if mysql returns any number of rows great than 0 there is a match
 
    return $results;
} // Added by [url=http://phpguruji.blogspot.com]Sujith[/url]
function query_db($query)
{
include("config.php");
}
?>
 

Good Luck..
Hey
Forum Newbie
Posts: 2
Joined: Wed Mar 25, 2009 10:54 pm

Re: Unexpected $end :/

Post by Hey »

Im horrible with the PHP mySQL functions and etc.
When I hit login it goes to a 404. Could anyone please tell me where it shows the page that you will be directed to when you hit login
sujithtomy
Forum Commoner
Posts: 46
Joined: Tue Mar 24, 2009 4:43 am

Re: Unexpected $end :/

Post by sujithtomy »

Hello,

Check the file exists which shows in browsers address bar after hits login button.
Post Reply