AdRock Posted September 11, 2007 Share Posted September 11, 2007 I thought I had this fixed but i didn't and it's driving me nuts. My edit profile page I have for my members works as expected until I try to check to see if the user is logged in first. I don't want to display the page is a user is not logged in. If i don't login and try to view the page, i get the message telliing me I'm not logged in etc so i know the is_authed function is checking to make sure i am logged in. If i take out the call to the function is_authed() the page works fine but if i leave that in i get this error message and the page dies PHP Fatal error: Call to undefined function check_form() in d:\\Apache\\htdocs\\jack\\edit_profile.php on line 54 This is the is_authed function function is_authed() { // Check if the encrypted username is the same // as the unencrypted one, if it is, it hasn't been changed if (isset($_SESSION['userid']) && md5($_SESSION['userid']) == $_SESSION['encrypted_id']) { return true; } else { return false; } } This is the edit_profile page <?php if (!is_authed()) { print ('You are not permitted to view this page, <a href="index.php">click here</a> to go back.'); } else { ?> <h2>Membership Registration</h2><hr /> <?php $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> <?php } 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"; } } } ?> Quote Link to comment Share on other sites More sharing options...
AdRock Posted September 11, 2007 Author Share Posted September 11, 2007 I got this problem worked out now by moving the check_form() function nearer th top of the page But how do i get rid of this notice? PHP Notice: Undefined index: submit Quote Link to comment Share on other sites More sharing options...
jagat21 Posted September 11, 2007 Share Posted September 11, 2007 Hi, try this <?php if (!is_authed()) { print ('You are not permitted to view this page, <a href="index.php">click here</a> to go back.'); } else { ?> <h2>Membership Registration</h2><hr /> <?php if(isset($_POST['submit'])) { $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> <?php } 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"; } } } ?> Quote Link to comment Share on other sites More sharing options...
AdRock Posted September 11, 2007 Author Share Posted September 11, 2007 Worked a treat...thanks jagat21 Quote Link to comment 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.