Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222340
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222345
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222367
Share on other sites

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 ".

Link to comment
https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222386
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/45749-confused-with-echo/#findComment-222459
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.