Page 1 of 1

code with unexpected $ parse error

Posted: Tue Aug 16, 2005 8:28 pm
by donnyziner
Can some kind soul tell me what I'm doing wrong with this code? It's throwing a "Parse error: parse error, unexpected $ in /home/virtual/site132/fst/var/www/html/validateloginsys.php on line 19" message. The db name, $login & $password have been left out for posting here).

It's a validation script to pass a user name and password to the db and redirect to a url based on the login.

Thank you - DZ

Code: Select all

<?php 
$connection = mysql_pconnect("localhost",$login,$password);
mysql_select_db("database_name", $connection);
$thisUser=$_POST['username']; 
$thisPass=$_POST['password']; 
$validateuser=mysql_query("select * from data where user='$thisUser' && pass='$thisPass'"); 
if (mysql_num_rows($validateuser)<1) { 
echo "Bad user name or password."; 
} 
else { 
while($row=mysql_fetch_array($validateuser)) { 
$okArea=$row["area"]; 
$areaForUser="/".$okArea."/index.html"; 
header("Location: $areaForUser"); 
exit; 
} 
mysql_free_result($validateuser); 
mysql_close($mysql_pconnect); 
?>

feyd | hey look at that, we have pretty colors! Use

Code: Select all

tags. [/color]

Posted: Tue Aug 16, 2005 8:31 pm
by nielsene
What line is line 19? If its the last line, you might want to try changing the $mysql_pconnect to $connection, since that's the name of the variable you used at line 2; and as mysql_pconnect is a function name it might be getting confused.

Posted: Tue Aug 16, 2005 8:32 pm
by donnyziner
nielsene wrote:What line is line 19?
It is, yes.
If its the last line, you might want to try changing the $mysql_pconnect to $connection, since that's the name of the variable you used at line 2; and as mysql_pconnect is a function name it might be getting confused.
I'll give that a try, thanks.

DZ

Posted: Tue Aug 16, 2005 8:37 pm
by donnyziner
If its the last line, you might want to try changing the $mysql_pconnect to $connection, since that's the name of the variable you used at line 2; and as mysql_pconnect is a function name it might be getting confused.
Nope. I changed it & still get the same error.

DZ

Posted: Tue Aug 16, 2005 8:49 pm
by nielsene
Hmm, not too sure what it could be, it looks fairly clean -- you might want to check your '}'s though. If that's the entire script, you're missing a closing brace, but I suspect you just posted a part of the script, so it should be alright.

mysql_close, will happend automatically at the end of the script .. you could try commenting out that line and seeing if the problem moves up one-line. mysql_close also defaults to the last used connection, so you could simply remove the $connection entirely in that call and see if it fixes things.

Posted: Tue Aug 16, 2005 9:27 pm
by donnyziner
nielsene wrote:Hmm, not too sure what it could be, it looks fairly clean -- you might want to check your '}'s though. If that's the entire script, you're missing a closing brace, but I suspect you just posted a part of the script, so it should be alright.
That is the whole script, actually... Where would the closing brace go?

Thanks,

DZ

Re: code with unexpected $ parse error

Posted: Tue Aug 16, 2005 9:32 pm
by nielsene

Code: Select all

<?php 
$connection = mysql_pconnect("localhost",$login,$password);
mysql_select_db("database_name", $connection);
$thisUser=$_POST['username']; 
$thisPass=$_POST['password']; 
$validateuser=mysql_query("select * from data where user='$thisUser' && pass='$thisPass'"); 
if (mysql_num_rows($validateuser)<1) { 
  echo "Bad user name or password."; 
} 
else { 
  while($row=mysql_fetch_array($validateuser)) { 
    $okArea=$row["area"]; 
    $areaForUser="/".$okArea."/index.html"; 
    header("Location: $areaForUser"); 
    exit; 
  }
} // <---------- This is the missing one 
mysql_free_result($validateuser); 
mysql_close($connection); 
?>

Posted: Wed Aug 17, 2005 2:08 pm
by donnyziner
Thanks for your time on this. I tried the change.

With the added } I now get this error:
Parse error: parse error, unexpected '{' in /home/virtual/site132/fst/var/www/html/validateloginsys.php on line 11

using this code:

Code: Select all

<?php 
$connection = mysql_pconnect("localhost",$login,$password); 
mysql_select_db("database_name", $connection); $thisUser=$_POST['username'];
$thisUser=$_POST['username'];
$thisPass=$_POST['password'];
$validateuser=mysql_query("select * from data where user='$thisUser' && pass='$thisPass'");
if (mysql_num_rows($validateuser)<1) {
echo "Bad user name or password.";
}
else {
  while($row=mysql_fetch_array($validateuser)) { //<---THIS IS LINE 11
    $okArea=$row["area"];
    $areaForUser="/".$okArea."/index.html";
    header("Location: $areaForUser");
    exit;
  }
}
mysql_free_result($validateuser);
mysql_close($connection);
?>

Posted: Wed Aug 17, 2005 2:10 pm
by donnyziner
Also - when I comment out the { on line 11, I get this error:

Parse error: parse error, unexpected T_STRING in /home/virtual/site132/fst/var/www/html/validateloginsys.php on line 12

When I comment out each following line the same error just moves down the script

Any help is appreciated - thanks. :?