Jump to content

user login, error on line 10, ')' unexpected


silverglade

Recommended Posts

Hi I have this user login, it gives me an error on the page as "unexpected syntax error, ')' . I cannot find the unnecessary extra parenthesis. please any help greatly appreciated. thank you.

 

<?php
session_start();
require("connect.php");
$post_username = $_POST['username'];
$post_password = $_POST['password'];

if($post_username && $post_password)
{

	if (strlen($post_username) >25) || strlen($post_password) < 15))
echo ("Username or password character length too long!")
else
    {

	//convert password to md5
	$post_password = md5($post_password);
	//query the database
	$login = sprintf("SELECT * FROM users WHERE username='$%s' AND password='%s'", mysql_real_escape_string($post_username),        mysql_real_escape_string($post_password);

       $rowcount = mysql_num_rows(mysql_query($login));

        if($rowcount==1)
        {
	  //log the user in
	  $_SESSION['user']=$post_username;
	  $_SESSION['user'].", you have been logged in! <a href="index.php">Return</a> to the main page.";
	}
	else
		 die("Incorrect username or password combination")

		 } //end top if
?>

Link to comment
https://forums.phpfreaks.com/topic/241133-user-login-error-on-line-10-unexpected/
Share on other sites

You are missing two "}" closing tag in the very end.

 

Alsi fixed this line:

if ((strlen($post_username) > 25) || (strlen($post_password) < 15))

 

I suggest you get some good IDE with syntax highlighting and possibility to see the starting and ending tags easily. Helps alot in errors like this.

 

edit: You are also missing the starting "{" in your else clause. Huh.

 

edit2: This line is also missing ending ")"

$login = sprintf("SELECT * FROM users WHERE username='$%s' AND password='%s'", mysql_real_escape_string($post_username),        mysql_real_escape_string($post_password));

 

Maybe pay attention a bit more in the opening and closing tags?

First of all: you cannot use  if($post_username && $post_password) as if it were 2 booleans. They are NOT !

Second:

<?php
if (strlen($post_username) >25) || strlen($post_password) < 15))
?>

 

<?php
if (
    (strlen($post_username) >25) ||
    (strlen($post_password) < 15)
   )
?>

 

Thank you everyone. I think I am going to do another tutorial because this guy cannot program. I find the tutorials on the net or even youtube for image galleries. One uses Dreamweaver to do it which I did not want. and the other can't code. I will have to search again. Thank God I have backups of my original website code before I started messing with these tutorials! thanks. :)

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.