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
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
Link to comment
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
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.