following code is giving a parse error,syntax error,$end error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kity
    New Member
    • Apr 2014
    • 1

    following code is giving a parse error,syntax error,$end error

    Code:
    <?php
    session_start();
    include("includes/config_db.php");
     // Define $myusername and $mypassword
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];
    
    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    
    $sql="SELECT * FROM members WHERE username='$myusername' and password=password('$mypassword')";
    $result=mysql_query($sql);
    
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row
    
    if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    $_SESSION['myusername'] = $myusername;
    $_SESSION['mypassword'] = $mypassword;
    //session_register("myusername");
    //session_register("mypassword");
    header("location:login_success.php");
    }
    else {
    ?>
    <table align="center" width="100%" border="0" cellpadding="0" cellspacing="1">
    <tr><td align="center"><br/><br/>
    <?
    echo "Wrong Username or Password";
    echo "<br/><input type=\"button\" name=\"Back\" value=\"Back\"  onclick=\"javascript: history.go(-1)\" />";
    ?>
    </td></tr></table>
    <?
    }
    
    ob_end_flush();
    ?>
    Last edited by Rabbit; Apr 14 '14, 04:30 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    - where are the line numbers you are getting your errors on?
    - why did you not use the '[CODE]' tags to post your code?

    - you should not use the short tag '<?', always use the long one '<php'

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      an $end error typically is caused by brace mismatch.

      Comment

      • datingstory
        New Member
        • Apr 2014
        • 2

        #4
        What is "?>" used for at line 30, 33, 36 and 38?

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          context change between PHP and HTML.

          Comment

          • koharu
            New Member
            • Apr 2014
            • 10

            #6
            Hi Kity.

            I've cleaned up the code you posted, please bare in mind that most cases of bad coding are due to messy coding being difficult even for the author to follow.

            Here's the cleaned code with comments on improvement. I have verified that the syntax is correct and working.
            Code:
            <?php
            session_start();
            include("includes/config_db.php");
             // Define $myusername and $mypassword
            $myusername = $_POST['myusername'];
            $mypassword = $_POST['mypassword'];
             
            // To protect MySQL injection (more detail about MySQL injection)
            $myusername = stripslashes($myusername);
            $mypassword = stripslashes($mypassword);
            $myusername = mysql_real_escape_string($myusername);
            $mypassword = mysql_real_escape_string($mypassword);
             
            $sql = "SELECT * FROM `members` WHERE `username` = '{$myusername}' and password = password('{$mypassword}')";
            $result = mysql_query($sql);
             
            // Mysql_num_row is counting table row
            //$count = mysql_num_rows($result); //You don't really need this, the MySQL query will return false if no results are found.
            // If result matched $myusername and $mypassword, table row must be 1 row
             
            	if($result){ //Check to see if $result is true or false.
            		// Register $myusername, $mypassword and redirect to file "login_success.php"
            		$_SESSION['myusername'] = $myusername;
            		$_SESSION['mypassword'] = $mypassword;
            		//session_register("myusername");
            		//session_register("mypassword");
            		header("location:login_success.php");
            	}else {
            		//Condense the echo statements. You don't have to escape the double quotes, just invert the quotes that Echo uses.
            		echo '<table align="center" width="100%" border="0" cellpadding="0" cellspacing="1">
            <tr><td align="center"><br/><br/>Wrong Username or Password<br/><input type="button" name="Back" value="Back"  onClick="javascript: history.go(-1)" /></td></tr></table>';
            		//Also try to ensure that you reduce the number of times you open or close a PHP tag, they can be rather tricky to follow. It also helps to keep those pesky PHP Parsers where opening and closing php tags is not allowed happy.
            	}
            	
            ob_end_flush();
            //	EOF
            ?>

            Comment

            Working...