Jump to content


Photo

unexpected T_Variable error I can't spot


  • Please log in to reply
7 replies to this topic

#1 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 16 September 2006 - 06:49 PM

This code is producing a T_Variable error on line 17.

$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";

Line 17 is

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


#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 16 September 2006 - 06:54 PM

I think that it should be like this.

$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";
   }
}

Hope that helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 16 September 2006 - 07:12 PM

That produces this error:

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

Which is the line right before it.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 September 2006 - 08:24 PM

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

Ken

#5 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 16 September 2006 - 09:30 PM

What I always do is something like this.

$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";
}

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

Good Luck,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#6 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 16 September 2006 - 10:04 PM

hate to consider completely changing the code but this should work a little better and be less redundant


$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;

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#7 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 16 September 2006 - 11:56 PM

I like that ^ zanus. I guess I learn something new every day.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#8 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 17 September 2006 - 04:43 PM

I need to make a small modification to it

this
if($index == "confirmPass" && $val == $tmp)
should be
if($index == "confirmPass" && $val != $tmp)

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users