j0seph Posted April 5, 2007 Share Posted April 5, 2007 Hi, How would i put <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> within an echo ' '; statement without the characters conflicting? Quote Link to comment https://forums.phpfreaks.com/topic/45749-confused-with-echo/ Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 You need to use string concatenation: <?php echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222218 Share on other sites More sharing options...
j0seph Posted April 5, 2007 Author Share Posted April 5, 2007 Cheers ken i'l check it out! Quote Link to comment https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222302 Share on other sites More sharing options...
j0seph Posted April 5, 2007 Author Share Posted April 5, 2007 Ok that seems to be good but the debugger now picks up the next line in the echo <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /> Do i have to stop the echo at the end of value=" then restart it after the end of the statement? My full code is this; <form action="' . $_SERVER['PHP_SELF'] . '" method="post"> <fieldset> <p><b>User Name:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p> <p><b>Password:</b> <input type="password" name="password" size="20" maxlength="20" /></p> <div align="center"><input type="submit" name="submit" value="Login" /></div> </fieldset></form> Quote Link to comment https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222340 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 You should write it like: <?php echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">'; ?> <fieldset> <p><b>User Name:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p> <p><b>Password:</b> <input type="password" name="password" size="20" maxlength="20" /></p> <div align="center"><input type="submit" name="submit" value="Login" /></div> </fieldset></form> Ken Quote Link to comment https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222345 Share on other sites More sharing options...
j0seph Posted April 5, 2007 Author Share Posted April 5, 2007 Thanks again Ken but the login form is nested within an php IF and ELSE statement if the user is not logged in then displayed the login form. However this means the form has to be within an echo statement?? <div id="Account"> <?php if (isset($_SESSION['user_id']) AND (substr($_SERVER['PHP_SELF'], -10) != 'logout.php')) { echo '<strong>Account Options</strong><br /> <a href="logout.php">Logout</a><br /> <a href="change_password.php">Change Password</a><br /> <a href="update_details.php">Update Details</a><br /> '; } else { echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post"> '; } Login form needs to be within the else { } but debugger throws up errors.. sorry for incorrect info Quote Link to comment https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222367 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 Please post all of you code as it is getting confusing as to where this "echo" statement is supposed to go. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222383 Share on other sites More sharing options...
JParishy Posted April 5, 2007 Share Posted April 5, 2007 echo "<div id=\"Account\">"; if (isset($_SESSION['user_id']) AND (substr($_SERVER['PHP_SELF'], -10) != 'logout.php')) { echo " <strong>Account Options</strong><br /> <a href=\"logout.php\">Logout</a><br /> <a href=\"change_password.php\">Change Password</a><br /> <a href=\"update_details.php\">Update Details</a><br /> "; } else { echo " <form action=\"$_SERVER['PHP_SELF']\" method=\"post\"> etc... "; } That should do. I tend to echo all html to the screen, that way variables don't interfere. Just make sure you do \" insted of just ". Quote Link to comment https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222386 Share on other sites More sharing options...
j0seph Posted April 5, 2007 Author Share Posted April 5, 2007 hmm this still throws up errors JParishy <form action=\"$_SERVER['PHP_SELF']\" method=\"post\"> Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/joea8764/public_html/testing/html/includes/footer.html on line 24 Quote Link to comment https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222459 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 Please post the exact error messages. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222460 Share on other sites More sharing options...
j0seph Posted April 5, 2007 Author Share Posted April 5, 2007 Sorry, I just modified the above post after you posted Quote Link to comment https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222467 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.