• PHP Help PHP Newbies
  • Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting ident

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\web\index.php on line 87

<?php

ini_set( "display_errors", 0); ?>
<?php include("inc/incfiles/header.inc.php"); ?>
<?php $reg = @$_POST['reg'];
//declaring variables to prevent errors
$fn = ""; //First Name
$ln = ""; //Last Name
$un = ""; //Username
$em = ""; //Email
$em2 = ""; //Email2
$pswd = ""; //Password
$pswd2 = ""; //Passsword2
$d = ""; //Sign up Date
$u_check = ""; //Check if username exists
//registration form
$fn = strip_tags(@$_POST['fname']);
$ln = strip_tags(@$_POST['lname']);
$un = strip_tags(@$_POST['username']);
$em = strip_tags(@$_POST['email']);
$em2 = strip_tags(@$_POST['email2']);
$pswd = strip_tags(@$_POST['password']);
$pswd2 =strip_tags(@$_POST['password2']); 
$d = date("Y-m-d"); //Year-Month-Day
if ($reg) {
if ($em==$em2) {
//check if user already exists
$u_check = mysql_query("SELECT `username` From `users` WHERE `username`='$un'");
//Count the amount of rows where username = $un
$check = mysql_num_rows($u_check);
if ($check == 0) {
//check all of the fields have been filed in
if ($fn&&$ln&&$un&&$em&&$em2&&$pswd&&$pswd2) {
//check that password match
if ($pswd==$pswd2) {
//check the maximum length of username/first name/last name does not exceed 25 characters
if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25) {
echo "The maximum limit for username/first name/last name is 25 characters!";
}
else 
{
//check the maximum length of password does not exceed 25 characters and is not less than 5 characters
if (strlen($pswd)>30||strlen($pswd)<5) {
echo "Your password must be between 5 and 30 characters long!";
}
else
{
//encrypt password and password2 using md5 before sending to database
$pswd = md5($pswd);
$pswd2 = md5($pswd2);
$query = mysql_query("INSERT INTO users VALUES (' ','$un','$fn','$ln','$em','$pswd','$d','O')");
die("<h2>Welcome to Friends For Life</h2>Login to your account to get started...");
}
}
}
else {
echo "Your password don't match!";
}
}
else
{
echo "Please fill in all of the fields";
}
}
else
{
echo "Username already taken ...";
}
}
else {
echo "Your E-mails don't match!";
}
}

?>
<?php //Login Script
if (isset($_POST["user_login"]) && isset($_POST["password_login"])) {
    $user_login = preg_replace('#[^A-Za-z0-9]#i','',$_POST["user_login"]); //filter everything but numbers and letters
    $password_login = preg_replace('#[^A-Za-z0-9]#i','',$_POST["password_login"]); //filter everything but numbers and letters
    $md5password_login = md5($password_login);
    $sql = mysql_query("SELECT id FROM users WHERE username='$user_login' AND password='$md5password_login' LIMIT 1');//query the person
//check for their existance
    $userCount = mysql_num_row($sql); //count the number of rows returned
    if ($userCount == 1) {
    while($row = mysql_fetch_array($sql)) {
                 $id = $row['id'];
}
     $_SESSION["id"] = $id;
     $_SESSION["user_login"] = $user_login;
     $_SESSION["password_login"] = $password_login;
     exit("<meta http-equiv=\"refresh\" content=\"0\">");
     }  else {
     echo 'That information is incorrect, try again';
     exit();
} }
?>
<br>
<br>
<br>
<table class="homepageTable">
   <tr>
     <td width="60%" valign="top">
     <h2>Join findFriends today!!</h2>
     <img src="img/3.gif" width="700">
      </td>
     <td width="40%" valign="top">
<h2>Member's Login...</h2>
<form>
<input type="text" size="15" name="user_login" id="user_login" placeholder="Username">
<input type="password" size="15" name="user_password" id="user_password" placeholder="Password"><br>
<input type="submit" name="button" id="button" value="Login to your account">     
<br><br> <h2>Sign up Below..!!</h2> <form action="#" method="post"> <input type="text" size="15" name="fname" placeholder="First Name" value="<?php echo $fn; ?>">
<input type="text" size="15" name="lname" placeholder="Last Name" value="<?php echo $ln; ?>">
<input type="text" size="15" name="username" placeholder="Username" value="<?php echo $un; ?>">
<input type="text" size="15" name="email" placeholder="Email" value="<?php echo $em; ?>">
<input type="text" size="15" name="email2" placeholder="Confirm Email" value="<?php echo $em2; ?>" >
<input type="password" size="15" name="password" placeholder="Password">
<input type="password" size="15" name="password2" placeholder="Confirm Passsword"> <br> <input type="submit" name="reg" value="Sign Up!">
</form>
</td> </tr>
</table> </body> </html>

$id = $row['id']; this is the error....how do i fix it?
i am new to php and i have no idea about this error
thank you!

    a few hints:

    1. often the error is above the line it's reported at
    2. pay attention to the syntax highlighting
    3. look at this line - you open with a double quote but close with a single quote
        $sql = mysql_query("SELECT id FROM users WHERE username='$user_login' AND password='$md5password_login' LIMIT 1');//query the person 
    //check for their existance 
    
    1. switch to mysqli or pdo

    hth

      hey thanks a lot..but i already fixed it...turns out to be a small error

      n can i ask you for another help please ? 😕

        Write a Reply...