Jump to content

Parse Error, why?


Zoofu

Recommended Posts

<?php

session_start();

include "./global.php";

 

if($_SESSION['uid']){

echo "You are already logged in, <a href=\"./logout.php\">logout</a>?\n";

}else {

 

if(!$_POST('submit')){

echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";

        echo "<form method=\"post\" action=\"./login.php\">\n";

        echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td></tr>\n";

        echo "<tr><td>Password</td><td><input type=\"password\" name=\"password\"></td></tr>\n";

        echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\"></td></tr>\n";

        echo "</form></table>\n";

}else {

$user = mss($_POST['username']);

$pass = $_POST['password'];

 

if($user && $pass){

$sql = "SELECT id FROM `users` WHERE `username`='".$user."'";

$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) > 0) {

$sql2 = "SELECT id FROM `users` WHERE `username`='".$user."' AND `password` ='".md5($pass)."'";

$res2 = mysql_query($sql2) or die(mysql_error());

if(mysql_num_rows($res2) > 0){

$row = mysql_fetch_assoc($res2);

$_SESSION['uid'] = $row['id'];

 

echo "You have logged in successfully!\n";

}else {

echo "Username or password are incorrect!\n";

}

}else {

echo "The Username you supplied does not exist!\n";

}

}else {

echo "You must fill in all fields!"

}

 

}

 

?>

 

 

Why is this giving me:

Parse error: syntax error, unexpected '{' in ----------- on line 26

Link to comment
https://forums.phpfreaks.com/topic/168137-parse-error-why/
Share on other sites

try

 

<?php
if($_SESSION['uid']){
   echo "You are already logged in, <a href=\"./logout.php\">logout</a>?\n";
}else {

if(!$_POST('submit')){//1
      echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
        echo "<form method=\"post\" action=\"./login.php\">\n";
        echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td></tr>\n";
        echo "<tr><td>Password</td><td><input type=\"password\" name=\"password\"></td></tr>\n";
        echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\"></td></tr>\n";
        echo "</form></table>\n";
   }else {
      $user = mss($_POST['username']);
      $pass = $_POST['password'];
      
         if($user && $pass){
            $sql = "SELECT id FROM `users` WHERE `username`='".$user."'";
            $res = mysql_query($sql) or die(mysql_error());
            if(mysql_num_rows($res) > 0) {
               $sql2 = "SELECT id FROM `users` WHERE `username`='".$user."' AND `password` ='".md5($pass)."'";
               $res2 = mysql_query($sql2) or die(mysql_error());
               if(mysql_num_rows($res2) > 0){
                  $row = mysql_fetch_assoc($res2);
                  $_SESSION['uid'] = $row['id'];
                  
                  echo "You have logged in successfully!\n";
               }else {
                  echo "Username or password are incorrect!\n";
               }
         }else {
            echo "The Username you supplied does not exist!\n";
         }
   }else {
      echo "You must fill in all fields!"
   }
   
  }

}//1

?>

Link to comment
https://forums.phpfreaks.com/topic/168137-parse-error-why/#findComment-886780
Share on other sites

Thanks for quick reply, but now:

 

Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/zoofune1/public_html/Htdocs/test.php on line 36

 

      $user = mss($_POST['username']);

whats this?

 

 

edit:

 

your ELSE at the very top isnt closed

 

post the updated scritp

Link to comment
https://forums.phpfreaks.com/topic/168137-parse-error-why/#findComment-886789
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.