PDA

View Full Version : PHP Shizen Again!



Hunter
March 13th, 2010, 09:31 PM
I don't see a problem in the code :/

Error:


Parse error: syntax error, unexpected '{', expecting '(' in /home/a9012858/public_html/admin/scripts/check_login.php on line 29
PHP:


<?php
session_start();

//Database connection
$dbhost = "hostname";
$dbuser = "username"; //Database username goes here
$dbpass = "password"; //Database password goes here
$dbname = "databasename"; //Database name

//Connect to database and set status variable for later use
$con = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$con) {
$mess = "Error connecting to database! Error: ".mysql_error(); // Error connection to mysql database
header("Location:../login.php?mess=$mess");
}

$uname= $_POST['username'];
$pword= md5($_POST['password']);
$remMe= $_POST['rememberme'];

if ($uname == "" || $uname == NULL) {
$mess = "Please enter your username!"; // No username has been entered
header("Location:../login.php?mess=$mess");
}

elseif ($upass == "" || $upass == NULL) {
$mess = "Please enter your password!"; //No password has been entered
header("Location:../login.php?mess=$mess");
} //LINE 29 IS HERE BY THE WAY ################################################## ###################

elseif {
//Tests have been passed
mysql_select_db($dbname, $con);
$query=mysql_query("SELECT * FROM users");

//Check if username and password matchs
while ($row=mysql_fetch_array($query)) {
$username=$row['username'];
$password=$row['password'];

if ($uname == $username && $pword == $password) {
// Username and password matches, make session variables
$_SESSION['username']=$uname;
$_SESSION['password']=md5($pword);

//Check is remember password has been set
if ($remMe==1) {
//Create cookies
setcookie("user", "$uname".md5($pword), time()+0*0*0*7); //Should set the cookie to expire in a week
}
//Now redirect to main page
$mess = "Login successfull!";
header("Location:../index.php?mess=$mess")
}
} //END While
}
?>

klange
March 14th, 2010, 12:01 AM
[COLOR=Black]i think you forgot your () for the Please enter your username.
lolwut? That's a variable assignment.

Anyway, you're problem is this:

elseif {You can't say "elseif [nothing]". Do you want else? Do you want a condition?

Also, your indenting sucks donkey nuts.

Cojafoji
March 14th, 2010, 03:05 AM
everyone makes mistakes. like i said, i'm a novice with php, and i was only trying to help. no need to be a dick.

Hunter
March 14th, 2010, 11:26 AM
Okay cheers. And what is wrong with my indenting?

klange
March 14th, 2010, 12:49 PM
Okay cheers. And what is wrong with my indenting?
It's terribly inconsistent.


<?php
session_start();

//Database connection
$dbhost = "hostname";
$dbuser = "username"; //Database username goes here
$dbpass = "password"; //Database password goes here
$dbname = "databasename"; //Database name

//Connect to database and set status variable for later use
$con = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$con) {
$mess = "Error connecting to database! Error: ".mysql_error(); // Error connection to mysql database
header("Location:../login.php?mess=$mess");
}

$uname= $_POST['username'];
$pword= md5($_POST['password']);
$remMe= $_POST['rememberme'];

if ($uname == "" || $uname == NULL) {
$mess = "Please enter your username!"; // No username has been entered
header("Location:../login.php?mess=$mess");
} elseif ($upass == "" || $upass == NULL) {
$mess = "Please enter your password!"; //No password has been entered
header("Location:../login.php?mess=$mess");
} elseif {
//Tests have been passed
mysql_select_db($dbname, $con);
$query=mysql_query("SELECT * FROM users");

//Check if username and password matchs
while ($row=mysql_fetch_array($query)) {
$username=$row['username'];
$password=$row['password'];

if ($uname == $username && $pword == $password) {
// Username and password matches, make session variables
$_SESSION['username']=$uname;
$_SESSION['password']=md5($pword);

//Check is remember password has been set
if ($remMe==1) {
//Create cookies
setcookie("user", "$uname".md5($pword), time()+0*0*0*7); //Should set the cookie to expire in a week
}
//Now redirect to main page
$mess = "Login successfull!";
header("Location:../index.php?mess=$mess")
}
} //END While
}
?>

That should be better.