Reaper0167 Posted January 31, 2009 Share Posted January 31, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/ Share on other sites More sharing options...
premiso Posted January 31, 2009 Share Posted January 31, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751641 Share on other sites More sharing options...
Reaper0167 Posted January 31, 2009 Author Share Posted January 31, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751645 Share on other sites More sharing options...
premiso Posted January 31, 2009 Share Posted January 31, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751646 Share on other sites More sharing options...
Reaper0167 Posted January 31, 2009 Author Share Posted January 31, 2009 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='';" /> Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751650 Share on other sites More sharing options...
trq Posted January 31, 2009 Share Posted January 31, 2009 Because you have single quotes within a single quoted string. Either escape them or use double quotes. This really is php basics. Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751652 Share on other sites More sharing options...
premiso Posted January 31, 2009 Share Posted January 31, 2009 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751654 Share on other sites More sharing options...
phpSensei Posted February 1, 2009 Share Posted February 1, 2009 You have session_start after the HTML you must call session_start() before anything is outputted to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751655 Share on other sites More sharing options...
Reaper0167 Posted February 1, 2009 Author Share Posted February 1, 2009 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='';" /> Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751665 Share on other sites More sharing options...
premiso Posted February 1, 2009 Share Posted February 1, 2009 Umm did you look at my post, I escaped the single quotes so you should not get the error. This is really basic php syntax as Thorpe said. Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751671 Share on other sites More sharing options...
Reaper0167 Posted February 1, 2009 Author Share Posted February 1, 2009 sorry premiso,, i skipped your post,,, my bad Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751674 Share on other sites More sharing options...
Reaper0167 Posted February 1, 2009 Author Share Posted February 1, 2009 with escaping the single quotes or even using double quotes, i don't get any errors, but when i click on the text field, my initial value is not removed. Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751676 Share on other sites More sharing options...
Reaper0167 Posted February 1, 2009 Author Share Posted February 1, 2009 bump ttt Quote Link to comment https://forums.phpfreaks.com/topic/143313-problem-with-echo/#findComment-751714 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.