Parse error in code

Asked

Viewed 166 times

1

Parse error: syntax error, Unexpected end of file in C: xampp htdocs network-social login.php on line 46

<?php
    include("db.php");

    if(isset($_POST['login'])){
       $email = $_POST['email'];
       $pass = $_POST['pass'];
       $verifica = mysql_query("SELECT * FROM users WHERE email = '$email'
       If (mysql_num_rows($verifica)<=0) {
           echo '<h3>Email ou Senha Incorretos!</h3>';
       }else{
          setcookie('login',$email);
          header('location: ./');
       }

     }

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8' />
    <title>CloseFriend - Fazer Login</title>
    <link href='https://fonts.googleapis.com/css?family=Arvo' rel='stylesheet' type='text/css'>
   <style type='text/css'>
   *{margin:0;padding:0;font-family: Arial;}
   body{text-align: center;}
   .logo{font-family: Lobster;color:#000000;font-size: 50px;margin:20px 0;}
   form{margin:20px 0;}
   input[type='text'],form input[type='password']{width:250px;height:40px;border:1px solid #999;padding:0 5px;border-radius:4px;margin:8px 0;font-size:17px;}
   input[type='submit']{width:260px;height:40px;border:1px solid #999;padding:0 5px;border-radius:4px;margin:8px 0;font-size:17px;color:#fff;font-weight:bold;background:#999;font-size:17px;cursor:pointer;}
   form h3{margin:20px 0;color:#999}
   form a{color:#000;text-decoration: none;}
   </style>
</head>
<body>
     <h1 class='logo'>CloseFriend</h1>
     <form method='POST'>
       <h2>Acessar sua conta</h2>
       <input type='email' placeholder='Digite seu E-mail'><br />
       <input type='password' placeholder='Senha'><br />
       <input type='submit' value=' Login'>
      </form>
      <h3>Não tem uma conta? <a href='login.php'>Criar uma conta</a></h3>
</body>
</html>
  • mysql_query("SELECT * FROM users WHERE email = '$email' missing a );, error when placing on the site or is just like that?

  • Where is line 46? Please edit the question and provide more information.

  • 1

    Consider using Prepared Statements not to be vulnerable to Mysql Injection attacks. You should also write the if in minuscule by consistency.

  • On the line "$verifies = mysql_query("SELECT * FROM users WHERE email = '$email'" should add a "); at the end E exchange If for if

2 answers

4

Of:

$verifica = mysql_query("SELECT * FROM users WHERE email = '$email'

To

$verifica = mysql_query("SELECT * FROM users WHERE email = '$email'");

Solved not?

Also save this message inside a array:

echo '<h3>Email ou Senha Incorretos!</h3>';

In this way:

$error[] = '<h3>Email ou Senha Incorretos!</h3>';

Use foreach to recover the message, example:

if(isset($error)) {
  foreach($error as $e) {
    echo $e;
  }
}

Note: put this one foreach within the HTML.

Your input, diminished, right, I saw that you stylized, inputs, text, password, but did not stylize input email

  • 1

    In this case it can be only one variable. Of course with the array is more versatile to include new messages, but currently would be unnecessary.

  • Well, I think it’s better, besides, she can do future checks, like, blank field, those things, and add the message.

  • where do I put this part? if(isset($error)) { foreach($error as $e) { echo $e; } }

  • It may be above </body>, remember to open tags <?php ?>

  • <H3>Don’t have an account? <a href='login.php'>Create an account</a></H3> if(isset($error)) { foreach($error as $e) { echo $e; } } </body> </html> like this?

  • That’s right, see if it works and comment here.

  • Guys, excuse my ignorance, I’m starting with the rsrs codes

  • The important thing is to try and succeed, but remember to search before asking any question is key. If it has been solved. Mark the answer as solved.

  • It was here people. Thanks for your help

  • @Julianaluiz click on the solved sign in the answer... this is the way to thank here in the community.

  • where is this?

  • See: http://prntscr.com/fse4m8

Show 7 more comments

3

You put all the code inside a string and the if with the capital "I". To fix, just put the "(aspas) at the end of the string you want and exchange the If for if:

<?php
    include("db.php");

    if(isset($_POST['login'])){
       $email = $_POST['email'];
       $pass = $_POST['pass'];
       $verifica = mysql_query("SELECT * FROM users WHERE email = '$email'");
       if (mysql_num_rows($verifica)<=0) {
           echo '<h3>Email ou Senha Incorretos!</h3>';
       }else{
          setcookie('login',$email);
          header('location: ./');
       }
     }
?>

Also, I recommend using either the Mysqli or the PDO instead of mysql_, since he is obsolete in newer versions of PHP.

Also note that your CSS is only styling type inputs text and password, to fix the size of the email box, you should add it to the CSS:

input[type='text'], form input[type='password'], form input[type='email'] {
    width: 250px;
    height: 40px;
    border: 1px solid #999;
    padding: 0 5px;
    border-radius: 4px;
    margin: 8px 0;
    font-size: 17px;
}
  • 2

    Can you comment on the fact that a echo of a single element h3 outside the HTML document itself. It is displayed, but it makes no sense to do so.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.