0

I have a JQuery Mobile app i am building and i am using PHP and MySQL to register and Login.

I populated the database with a user and tried to login using the php script i wrote, however, i get the following error:

<br />
<b>Parse error</b>:  syntax error, unexpected '}' in <b>/home/u426137825/public_html/login.php</b> on line <b>26</b><br />

I really don't understand this one.

Line 26 is the closing bracket after the IF statement checking the rows returned.

Here is my PHP code:

<?php

$email = TRIM($_REQUEST['email']);
$pword = TRIM($_REQUEST['password']);


if( isset($email) && isset($password)){

    $pword = mysqli_real_escape_string($con, $pword);
    $email = mysqli_real_escape_string($con, $email);

    require('includes/dbcon.php');

    $sql = mysqli_query($con, "SELECT ALL from users WHERE email = '$email' AND BINARY password = '$pword'");

    $checkrows=mysqli_num_rows($sql);
    $row = mysqli_fetch_array($sql);
}

        $userID = $row('id');
        $name = $row('username');

            if($checkrow>0){
                mysqli_close($con);
                header("location:index.html#mapPage")
}

else{
  $loginError = "Wrong Username or Pasword";  
    echo $loginError;
}

Any help on this issue would be appreciated.

Regards

red_starz
  • 49
  • 7
  • You forgot a semicolon behind 'header("location:index.html#mapPage")'. And then you will have to change the parenthesis from $row('id') to $row['id'] because these are arrays. And the variable '$checkrow' should be '$checkrows' in the second occurence. And you can't change the location in the header with a hash in the end, because the hash is handled by the browser and will not appear on redirect. – Martin Cup Nov 23 '16 at 23:54
  • thank you for the advice, from the documentation that fred -ii- provided i discovered the missing semicolon. – red_starz Nov 23 '16 at 23:59
  • Also, i have tried to research a way to redirect in Jquery mobile using PHP, im not quite there yet thought, any ideas? – red_starz Nov 24 '16 at 00:00
  • 1
    **WARNING**: Writing your own access control layer is not easy and there are many opportunities to get it severely wrong. Please, do not write your own authentication system when any modern [development framework](http://codegeekz.com/best-php-frameworks-for-developers/) like [Laravel](http://laravel.com/) comes with a robust [authentication system](https://laravel.com/docs/5.2/authentication) built-in. At the absolute least follow [recommended security best practices](http://www.phptherightway.com/#security) and **never store passwords as plain-text**. – tadman Nov 24 '16 at 00:01
  • 1
    **WARNING**: When using `mysqli` you should be using [parameterized queries](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [`bind_param`](http://php.net/manual/en/mysqli-stmt.bind-param.php) to add user data to your query. **DO NOT** use manual escaping and string interpolation or concatenation to accomplish this because you will create severe [SQL injection bugs](http://bobby-tables.com/) if you ever forget to properly escape something. – tadman Nov 24 '16 at 00:01
  • tadman is right. You should use a PHP-Framework, like cakePHP or Laravel to authenticate. I prefer cakePHP. Learning such a framework will make your life so much easier in the end. If you want to redirect in jQuery mobile you should get the response from the server and then make the redirect in javascript. – Martin Cup Nov 24 '16 at 00:04
  • Guys, thanks for the advice but this is a personal project to develop my abilities. these simplistic access controls are fine for the moment and can be improved with hashing etc in the future. I have used hashing before but don't feel the need right now. – red_starz Nov 24 '16 at 00:05
  • I will, however have a look at cakePHP! – red_starz Nov 24 '16 at 00:06
  • Learning core PHP is an essential thing if you want to be an effective developer using that language, but there's a ton of stuff the core simply doesn't do. That's why there's around a dozen high-quality, community supported frameworks that can help you. Each gives you a lot of guidance on how to structure applications, tools to make you more productive, and you can still use all of core PHP if you want to. If this is more than a quick hack, picking one that suits your style and needs will help considerably in your learning. – tadman Nov 24 '16 at 06:05
  • I'm thinking about using Code Igniter. Any advice regarding this? – red_starz Nov 24 '16 at 23:01

0 Answers0