Jump to content

[SOLVED] Problem displaying members edit profile page


Recommended Posts

I have an edit profile page for my memebership system which works fine until i call a function to make sure that the user is logged in before displaying the content with their details.

 

When I log in and go onto the edit profile page, all the form fields are there but as soon as I click submit the page goes blank.  I don't have this problem if I don't use the function but how else am i supposed to only display the page to registered and logged in users?

 

Here is the function to check whether a user is logged in

function is_authed_user()
{
     // Check if the encrypted username is the same
     // as the unencrypted one, if it is, it hasn't been changed
     if (isset($_SESSION['username']) && (md5($_SESSION['username']) == $_SESSION['encrypted_name']))
     {
          return true;
     }
     else
     {
          return false;
     }
}[code]

and here is the edit profile page.
<?php
    if (!is_authed_user()) 
    {
print ('You are not permitted to view this page, <a href="index.php">click here</a> to go back.');
    }
    else
    {
echo"<h2>Edit Profile</h2><hr />";

$submit = $_POST['submit'];

function show_form() { 
    global $_POST, $print_again, $error;
    global $first_name, $last_name, $interests, $username, $newsletter; 

    ?> 
    <form method="post" id="login" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
    	    	<fieldset>
    		    <legend>Username</legend>
	    <p class="hint">Please enter a username for your user account. Note that username should be between 4 and 30 characters.</p>
    		    <p><label for="username">Username:</label>
    		    <input type="text" <?php error_bool($error, "username"); ?> title="Please enter a username" id="username" name="username" size="30" value="<?php echo $username; ?>" /></p>
    	    	</fieldset>
    	    	<fieldset>
	    <legend>About You</legend>
    		    <p><label for="first_name">Forename:</label>
    		    <input type="text" <?php error_bool($error, "first_name"); ?> title="Please enter your first name" id="first_name" name="first_name" size="30" value="<?php echo $first_name; ?>" /></p>

    		    <p><label for="last_name">Surname:</label>
    		    <input type="text" <?php error_bool($error, "last_name"); ?> title="Please enter your last name" id="last_name" name="last_name" size="30" value="<?php echo $last_name; ?>" /></p>

	    <p class="hint">Please enter any interests/hobbies you have (optional).</p>
    		    <p><label for="interests">Your Interests:</label>
    		    <input type="text" title="Please enter any interests/hobbies you have" id="interests" name="interests" size="30" value="<?php echo $interests; ?>" /></p>
    	    	</fieldset>
    	    	<fieldset>
    		    <legend>Newsletter</legend>
	    <p class="hint">Sign up for jackgodfrey.org.uk newsletter. This newsletter includes what forthcoming events we are arranging, the latest Honeylands news and our latest news. You can Opt-out at any time....so sign up and give it a try!!</p>
    		    <p><label for="newsletter">Newsletter:</label>
    		    <input style="border:none" type="radio" value="yes" id="newsletter" checked="checked" name="newsletter" />Opt-in <input style="border:none" type="radio" value="no" name="newsletter" />Opt-out</p>
    	    	</fieldset>
    		    <p><label for="Submit" style="width: 20px"> </label>
    		    <input type="submit" name="submit" value="Edit Profile" class="sendbutton" />
    		    <input type="reset" value="Reset Fields" class="sendbutton" /></p>
    </form>
    <? 
} 
if(isset($submit)) { 
    check_form(); 
}
else 
{ 
    show_form(); 
} 

function check_form() { 
    global $_POST, $error, $print_again;
    global $first_name, $last_name, $username, $newsletter; 

    $first_name = check_input($_POST['first_name']);
    $last_name = check_input($_POST['last_name']);
    $interests = check_input($_POST['interests']);
    $username = check_input($_POST['username']);
    $newsletter = $_POST['newsletter'];

    $error['first_name'] = false;

    if(empty($first_name)) { 
        $error['first_name'] = true; 
         $print_again = true; 
        $message="<li>The <span><b>Forename</b></span> field is empty</li>"; 
    }
    else if(!ereg("^[A-Za-z]{2,30}$",$first_name)) {
	$error['first_name'] = true; 
         $print_again = true; 
        $message="<li><span><b>Forename</b></span> must contain letters only</li>";
    }

    if(empty($last_name)) { 
        $error['last_name'] = true; 
         $print_again = true; 
        $message.="<li>The <span><b>Surname</b></span> field is empty</li>"; 
    }
    else if(!ereg("^[A-Za-z\-]{2,30}$",$last_name)) {
	$error['last_name'] = true; 
         $print_again = true; 
        $message.="<li><span><b>Surname</b></span> must contain letters only</li>";
    }

    if(empty($username)) { 
        $error['username'] = true; 
         $print_again = true; 
        $message.="<li>The <span><b>Username</b></span> field is empty</li>"; 
    }
    else if( mysql_num_rows(mysql_query("SELECT username FROM users WHERE username = '$username'")) ) {
        $error['username'] = true; 
         $print_again = true; 
        $message.="<li>The username you have selected has already been used by another member in our database. Please choose a different Username!</li>";
	}
    else if(!ereg("^[A-Za-z0-9 \-]{4,30}$",$username)) {
	$error['username'] = true; 
         $print_again = true; 
        $message.="<li><span><b>Username</b></span> must contain letters and numbers only</li>";
    }  

    if($print_again)
    {
   	echo "<h2 class=\"errorhead\">There has been an error:</h2><p>You forgot to enter the following field(s)</p>
   	    <ul id=\"validation\">$message</ul>";
   	show_form(); 
    }
    else
    {

	// Stop the form being used from an external URL
    	// Get the referring URL
    	$referer = $_SERVER['HTTP_REFERER'];
    	// Get the URL of this page
    	$this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
    	// If the referring URL and the URL of this page don't match then
    	// display a message and don't send the email.
    	if ($referer != $this_url)
 	{
            echo "You do not have permission to use this script from another URL.<br />";
	    echo "If you are behind a firewall please check your referrer settings.";
            exit;
        }
	echo "done";
    } 
} 
      }
?>

[/code]

HA HA HA HA HA HA!!! ;D ;D ;D ;D ;D

 

sucks to be you!!! :P

 

You php code crashed. When you get a blank page it means it crashed. Check your log files on your server. If you have a shared hosting server like I do don't expect any log files. :-\

 

HA HA HA HA!  ;D ;D ;D ;D(I'm only laughing cause this happended to me like a week ago and I got super pissed and started ripping my hair out).

 

;D ;D ;D HA HA HA HA ;D ;D ;D

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.