Jump to content

problem with echo


Reaper0167

Recommended Posts

this doesn't work

echo '<?php 
	   		 <form name="form1" method="post" action="login.php">
			 <input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />
			 <input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />
			 <input type="submit" name="submit" id="submit" value="Login">
			 <br />
			 Not registered? <a href="register.php">Register Now!</a>
			 </form>';
  	    		 ?>

but this does work,, what is going on?

<?php
<form name="form1" method="post" action="login.php">
<input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />
<input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />
<input type="submit" name="submit" id="submit" value="Login">
<br />
Not registered? <a href="register.php">Register Now!</a>
</form>
?>

when i echo out the form i get an error

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in D:\-----\-----\html\------\index.php on line 35

here is line 35

<input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />

should something be different when echoing out the form while using the onfocus

 

 

Link to comment
Share on other sites

Echo is not inside the php tags. The second code should not work. Try this:

 

<?php 
                echo '<form name="form1" method="post" action="login.php">
             <input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />
             <input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />
             <input type="submit" name="submit" id="submit" value="Login">
             <br />
             Not registered? <a href="register.php">Register Now!</a>
             </form>';
                ?>

 

This would also work:

 

<?php
echo <<<FORM 
             <form name="form1" method="post" action="login.php">
<input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />
<input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />
<input type="submit" name="submit" id="submit" value="Login">
<br />
Not registered? <a href="register.php">Register Now!</a>
</form>
FORM;
?>

 

The 2nd is using HEREDOC syntax.

Link to comment
Share on other sites

here is the full code for the table i have everything in

<?php // this start tag is not in my code,, just put it there for you
<table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th height="297" scope="col"><div id="header"><img src="images08/header.png" alt="header" width="421" height="47" /></div>
      <div id="apDiv1">
        <?php
        session_start();
        if(isset($_SESSION['auth']))
        {
      	  echo $_SESSION['message'];
        }
        else
        {
      	   echo '<?php 
	   		 <form name="form1" method="post" action="login.php">
			 <input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />
			 <input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />
			 <input type="submit" name="submit" id="submit" value="Login">
			 <br />
			 Not registered? <a href="register.php">Register Now!</a>
			 </form>';
  	    		 ?>
	}
	    ?>
    </div></th>
  </tr>
</table>
?> // same with this tag

now you can get a better look at why it is not working.

Link to comment
Share on other sites

            echo '
                <form name="form1" method="post" action="login.php">
             <input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />
             <input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />
             <input type="submit" name="submit" id="submit" value="Login">
             <br />
             Not registered? <a href="register.php">Register Now!</a>
             </form>';
                // this was causing an issue?>

 

You had unessarcy <?php tag inside the echo tag. Remove that. Also note you need to remove the ?> The echo statement can be echoed and must be echoed inside php tags and since you are already in php, that was causing an issue.

Link to comment
Share on other sites

i removed the php tags.here i what i got.. still an error.

<table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th height="297" scope="col"><div id="header"><img src="images08/header.png" alt="header" width="421" height="47" /></div>
      <div id="apDiv1">
        <?php
        session_start();
        if(isset($_SESSION['auth']))
        {
      	  echo $_SESSION['message'];
        }
        else
        {
      	   echo '<form name="form1" method="post" action="login.php">
			 <input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />
			 <input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />
			 <input type="submit" name="submit" id="submit" value="Login">
			 <br />
			 Not registered? <a href="register.php">Register Now!</a>
			 </form>';
  	    }
	    ?>
    </div></th>
  </tr>
</table>

still getting an error with this line

<input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />

 

Link to comment
Share on other sites

The single quotes are causing the issue, they need escaped:

 

            echo '<form name="form1" method="post" action="login.php">
             <input name="username" type="text" id="username" value="User ID" onfocus="this.value=\'\';"  />
             <input name="password" type="password" id="password" value="Password" onfocus="this.value=\'\';" />
             <input type="submit" name="submit" id="submit" value="Login">
             <br />
             Not registered? <a href="register.php">Register Now!</a>
             </form>';

Link to comment
Share on other sites

don't understand why that would make a difference. here is the code with the onfocus for the text boxes removed. everything loads just fine.

<table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th height="297" scope="col"><div id="header"><img src="images08/header.png" alt="header" width="421" height="47" /></div>
      <div id="apDiv1">
        <?php
        session_start();
        if(isset($_SESSION['auth']))
        {
      	  echo $_SESSION['message'];
        }
        else
        {
      	   echo '<form name="form1" method="post" action="login.php">
			 <input name="username" type="text" id="username" value="User ID"  />
			 <input name="password" type="password" id="password" value="Password"  />
			 <input type="submit" name="submit" id="submit" value="Login">
			 <br />
			 Not registered? <a href="register.php">Register Now!</a>
			 </form>';
  	    }
	    ?>
    </div></th>
  </tr>
</table>

i get the error when the 2 lines are changed to this

 

<input name="username" type="text" id="username" value="User ID" onfocus="this.value='';" />

<input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />

 

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.