AdRock Posted September 11, 2007 Share Posted September 11, 2007 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] Link to comment https://forums.phpfreaks.com/topic/68765-solved-problem-displaying-members-edit-profile-page/ Share on other sites More sharing options...
TheFilmGod Posted September 11, 2007 Share Posted September 11, 2007 HA HA HA HA HA HA!!! ;D ;D sucks to be you!!! 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(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 HA HA HA HA ;D Link to comment https://forums.phpfreaks.com/topic/68765-solved-problem-displaying-members-edit-profile-page/#findComment-345671 Share on other sites More sharing options...
AdRock Posted September 11, 2007 Author Share Posted September 11, 2007 How did you fix it then? I checked my logs and this is the error PHP Fatal error: Call to undefined function check_form() in d:\\Apache\\htdocs\\jack\\edit_profile.php on line 49 Link to comment https://forums.phpfreaks.com/topic/68765-solved-problem-displaying-members-edit-profile-page/#findComment-345687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.