simcoweb Posted September 16, 2006 Share Posted September 16, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/20996-unexpected-t_variable-error-i-cant-spot/ Share on other sites More sharing options...
tomfmason Posted September 16, 2006 Share Posted September 16, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/20996-unexpected-t_variable-error-i-cant-spot/#findComment-93148 Share on other sites More sharing options...
simcoweb Posted September 16, 2006 Author Share Posted September 16, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20996-unexpected-t_variable-error-i-cant-spot/#findComment-93160 Share on other sites More sharing options...
kenrbnsn Posted September 16, 2006 Share Posted September 16, 2006 Can you post the rest of the lines leading up to these lines? The error could actually be before them.Ken Quote Link to comment https://forums.phpfreaks.com/topic/20996-unexpected-t_variable-error-i-cant-spot/#findComment-93189 Share on other sites More sharing options...
tomfmason Posted September 16, 2006 Share Posted September 16, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/20996-unexpected-t_variable-error-i-cant-spot/#findComment-93213 Share on other sites More sharing options...
Zane Posted September 16, 2006 Share Posted September 16, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/20996-unexpected-t_variable-error-i-cant-spot/#findComment-93226 Share on other sites More sharing options...
tomfmason Posted September 16, 2006 Share Posted September 16, 2006 I like that ^ zanus. I guess I learn something new every day. Quote Link to comment https://forums.phpfreaks.com/topic/20996-unexpected-t_variable-error-i-cant-spot/#findComment-93283 Share on other sites More sharing options...
Zane Posted September 17, 2006 Share Posted September 17, 2006 I need to make a small modification to itthis[code]if($index == "confirmPass" && $val == $tmp)[/code]should be[code]if($index == "confirmPass" && $val != $tmp)[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20996-unexpected-t_variable-error-i-cant-spot/#findComment-93560 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.