MrXortex Posted August 5, 2012 Share Posted August 5, 2012 Hello. I am trying to create a registeration system on my website using PHP and MySQL. BUt whenever I put <?php ?> tags and start coding and test it, I get this error Parse error: syntax error, unexpected T_STRING on line 39 Here is my code: <?php $form = "<form method="post" action="signup-p.php" id="signupform"> <div class="form"> <div class="fieldset"> <input name="signup_form" type="hidden" /> <div class="input"> <label for="username">Username</label> <input type="text" name="user" id="username" value="" /> </div> <div class="input"> <label for="email">E-mail</label> <input type="text" name="email" id="email" value="" /> </div> <div class="input"> <label for="email_confirm">Confirm E-mail</label> <input type="text" name="email_confirm" id="email_confirm" value="" /> </div> <div class="input"> <label for="password">Password</label> <input type="password" name="password" id="password" /> </div> <div class="input"> <label for="password_confirm">Confirm password</label> <input type="password" name="password_confirm" id="password_confirm" /> </div> </div> <div class="button"><strong><input type="submit" class="submit" name="registerbtn" value="Sign up" /></strong></div> </div> </form>" ?> The code error on line 39: $form = "<form method="post" action="signup-p.php" id="signupform"> If you need more details, let me know. Please help me fix the issue. Thanks. Hassan. Quote Link to comment https://forums.phpfreaks.com/topic/266708-parse-error-syntax-error-unexpected-t_string/ Share on other sites More sharing options...
jazzman1 Posted August 5, 2012 Share Posted August 5, 2012 @hassan, check this out -> http://php.net/manual/en/language.types.string.php $form = <<<EOD "<form method="post" action="signup-p.php" id="signupform"> <div class="form"> <div class="fieldset"> <input name="signup_form" type="hidden" /> <div class="input"> <label for="username">Username</label> <input type="text" name="user" id="username" value="" /> </div> <div class="input"> <label for="email">E-mail</label> <input type="text" name="email" id="email" value="" /> </div> <div class="input"> <label for="email_confirm">Confirm E-mail</label> <input type="text" name="email_confirm" id="email_confirm" value="" /> </div> <div class="input"> <label for="password">Password</label> <input type="password" name="password" id="password" /> </div> <div class="input"> <label for="password_confirm">Confirm password</label> <input type="password" name="password_confirm" id="password_confirm" /> </div> </div> <div class="button"><strong><input type="submit" class="submit" name="registerbtn" value="Sign up" /></strong></div> </div> </form>" EOD; Quote Link to comment https://forums.phpfreaks.com/topic/266708-parse-error-syntax-error-unexpected-t_string/#findComment-1366958 Share on other sites More sharing options...
jcbones Posted August 5, 2012 Share Posted August 5, 2012 Yes, I agree with jazzman, use heredoc syntax, or break out of PHP and use straight HTML since there are no variables in there. The reason why you get that error, is you started the string with a double quote ("), so the next time PHP sees another double quote, it thinks you are ending your string. Other than changing to heredoc, or nowdoc, you can start the string with a single quote ('), or escape the double quotes like (\"). Valid: <?php //syntax highlighting $form = "<form method=\"post\" action=\"signup-p.php\" id=\"signupform\">"; //will populate variable inside the string. //or $form = '<form method="post" action="signup-p.php" id="signupform">'; //will not populate variables in the string. //or //will populate variables in the string. $form = <<<string <form method="post" action="signup-p.php" id="signupform"> string; //or //will not populate variables in the string. $form = <<<'string' <form method="post" action="signup-p.php" id="signupform"> string; Quote Link to comment https://forums.phpfreaks.com/topic/266708-parse-error-syntax-error-unexpected-t_string/#findComment-1366962 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.