Jump to content

Archived

This topic is now archived and is closed to further replies.

simcoweb

unexpected T_Variable error I can't spot

Recommended Posts

This code is producing a T_Variable error on line 17.

[code]$message = "";
if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['confirmPass'])) {
  if(empty($_POST['username'])
  $message .= "You did not complete the username field properly.<br>\n";
  if(empty($_POST['password'])
  $message .= "You did not enter a correct password.<br>\n";
  if(empty($_POST['confirmPass'])
  $message .= "Your password entries did not match.<br>\n";[/code]

Line 17 is

[code]$message .= "You did not complete the username field properly.<br>\n";[/code]

Share this post


Link to post
Share on other sites
I think that it should be like this.

[code=php:0]
$message = "";
if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['confirmPass'])) {
   if(empty($_POST['username'])) {
   $message .= "You did not complete the username field properly.<br>\n";
   }
   if(empty($_POST['password'])) {
   $message .= "You did not enter a correct password.<br>\n";
   }
   if(empty($_POST['confirmPass'])) {
   $message .= "Your password entries did not match.<br>\n";
   }
}[/code]

Hope that helps,
Tom

Share this post


Link to post
Share on other sites
That produces this error:

[code]Parse error: parse error, unexpected '{' in /home2/wwwplat/public_html/register.php on line 16[/code]

Which is the line right before it.

Share this post


Link to post
Share on other sites
Can you post the rest of the lines leading up to these lines?  The error could actually be before them.

Ken

Share this post


Link to post
Share on other sites
What I always do is something like this.

[code=php:0]
$username = mysql_real_escape_string(trim($_POST['username']));
$password = mysql_real_escape_string(trim($_POST['password']));
$confirm_pass = mysql_real_escape_strin(trim($_POST['confirmPass']));

if ((!$username) || (!$password) || (!$confirm_pass)) {
  if (!$username) {
      $message .= "something":
  }
    //continue
}

if ($password !== $confirm_pass) {
    $message .= "something_else";
}
[/code]

I would suggest that you santize the users inputed data before and database calls or updates. 

Good Luck,
Tom

Share this post


Link to post
Share on other sites
hate to consider completely changing the code but this should work a little better and be less redundant


[code]$message = null;
$tmp = null;

foreach($_POST as $index=>$value) {
  if($index == "username" && empty($val))
        $message .= "You did not complete the username field properly.<br>\n";

  if(($index == "password" && empty($val)) || ($index == "confirmPass" && empty($val)))
        $message .= "You did not enter a correct password.<br>\n";
  else if($index == "password" && !empty($val))
        $tmp = $val;


  if($index == "confirmPass" && $val == $tmp)
        $message .= "Your password entries did not match.<br>\n";
}
echo $message;[/code]

Share this post


Link to post
Share on other sites
I need to make a small modification to it

this
[code]if($index == "confirmPass" && $val == $tmp)[/code]
should be
[code]if($index == "confirmPass" && $val != $tmp)[/code]

Share this post


Link to post
Share on other sites

×

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.