Jump to content

Parse error: syntax error, unexpected T_STRING


MrXortex

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;

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.