Results 1 to 8 of 8

Thread: header("location: member_profile.php?id=$id"); not working

  1. #1
    Join Date
    Mar 2014

    header("location: member_profile.php?id=$id"); not working

    if ($_POST['email']) {
    //Connect to the database through our include
    include_once "connect_to_mysql.php";
    $email = stripslashes($_POST['email']);
    $email = strip_tags($email);
    $email = mysql_real_escape_string($email);
    $password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
    $password = md5($password);
    // Make query and then register all database data that -
    // cannot be changed by member into SESSION variables.
    // Data that you want member to be able to change -
    // should never be set into a SESSION variable.
    $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$password' AND emailactivated='1'");
    $login_check = mysql_num_rows($sql);
    if($login_check > 0){
    while($row = mysql_fetch_array($sql)){
    // Get member ID into a session variable
    $id = $row["id"];
    $_SESSION['id'] = $id;
    // Get member username into a session variable
    $username = $row["username"];
    $_SESSION['username'] = $username;
    // Update last_log_date field for this member now
    mysql_query("UPDATE members SET lastlogin=now() WHERE id='$id'");
    // Print success message here if all went well then exit the script
    header("location: member_profile.php?id=$id");
    } // close while
    } else {
    // Print login failure message to the user and link them back to your login page
    print '<br /><br /><font color="#FF0000">No match in our records, try again </font><br />
    <br /><a href="login.php">Click here</a> to go back to the login page.';
    }// close if post
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Login to your profile</title>
    <script type="text/javascript">
    <!-- Form Validation -->
    function validate_form ( ) {
    valid = true;
    if ( document.logform.email.value == "" ) {
    alert ( "Please enter your User Name" );
    valid = false;
    if ( document.logform.pass.value == "" ) {
    alert ( "Please enter your password" );
    valid = false;
    return valid;
    <!-- Form Validation -->
    <div align="center">
    <h3><br />
    <br />
    Log in to your account here<br />
    <br />
    <table align="center" cellpadding="5">
    <form action="login.php" method="post" enctype="multipart/form-data" name="logform" id="logform" onsubmit="return validate_form ( );">
    <td class="style7"><div align="right">Email Address:</div></td>
    <td><input name="email" type="text" id="email" size="30" maxlength="64" /></td>
    <td class="style7"><div align="right">Password:</div></td>
    <td><input name="password" type="password" id="password" size="30" maxlength="24" /></td>
    <td><input name="Submit" type="submit" value="Login" /></td>

  2. #2
    Join Date
    Mar 2014
    after i submit the login page i get a blank page, kindly help me out?

  3. #3
    Join Date
    Feb 2014
    Try checking the error logs or running these 2 lines at the top of the page:

    PHP Code:
        error_reporting(E_ALL E_NOTICE);
    Generally, I use JavaScript as an alternative to PHP's header when trying to re-direct users to a different page. It doesn't look as pretty but works. Chances are, the error you'll see will say something along the lines of trying to send header after already sent.

  4. #4
    Join Date
    Mar 2014
    after following your instructions i get the below errors,

    Deprecated: Function ereg_replace() is deprecated in /home/vol10_8/myfreepage.tk/mfpt_14268580/htdocs/login.php on line 14

    Fatal error: Call to undefined function session_register() in /home/vol10_8/myfreepage.tk/mfpt_14268580/htdocs/login.php on line 26

  5. #5
    Join Date
    Aug 2004
    Well, fatal errors are ... fatal, so it's time to join the PHP 5 world and stop using session_register().

    Your scripts should just be using session_start() on each page that needs read and/or write access to the session data, and access all such data via the $_SESSION super-global array.

    Also, while it's currently not a fatal error, it would be a good idea to migrate all use of ereg_*() functions to their corresponding preg_*() functions.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  6. #6
    Join Date
    Mar 2014
    o.k thankyou, i look forward to join php 5.

  7. #7
    Join Date
    Jul 2013
    Voorheesville NY USA
    The blank page is probably because you have errors but you don't have error checking turned on in order to see them. Also as nogdog says, don't use session_register. I suggest you do some reading in the manual. Here's an example of some knowledge there:

    // Use of session_register() is deprecated
    $barney = "A big purple dinosaur.";

    // Use of $_SESSION is preferred, as of PHP 4.1.0
    $_SESSION["zim"] = "An invader from another planet.";

    Other suggestions:
    Use the code tags for this forum to post your code in.

    Write neater looking code - try indenting some lines like:
    PHP Code:
    if (condition

    Don't you agree that this is much more readable?

    Another thing: Why are you using stripslashes on an input field? Who put the slashes there?

  8. #8
    Join Date
    Feb 2014
    The error output is telling you exactly what the problems are. First, ereg_replace() is depreciated, so you shouldn't be using it to start with. Second, you don't need session_register(), it's outdated, just use $_SESSION['something'] and have session_start() at each page (if you have php files included in other php files that start a session, there will be a notice saying it's been started but is being ignored). Take a look at the php.net manual and it's very handy to have open in another window as you're coding.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center