Jump to content

unexpected T_Variable error I can't spot


simcoweb

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]
Link to comment
https://forums.phpfreaks.com/topic/20996-unexpected-t_variable-error-i-cant-spot/
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
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
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]

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.