Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Form Entry and Redirection!

    Ok, i've tried to work this one out on my own. Really wanted to. But I really can't! The problem is that on my site, the user needs to be able to change their password, so on the page where i've put the form to change it, the address is (/usersettings.php?user=$session->username). This obviously means their username goes on the end of the address. However, when the form is submitted, it redirects the user to (/usersettings.php), without the (?user=$session->username) on the end. This is where the problem is lying, because then the user is getting an error message, saying "Username Not Found".

    I've included the code;
    Firstly the HTML:

    Code:
    <?
    
    if(isset($_SESSION['usersettings'])){
       unset($_SESSION['usersettings']);
       
       echo "<h1>User Account Edit Success!</h1>";
       echo "<p><b>$session->username</b>, your account has been successfully updated. "
           ."<a href=\"main.php\">Main</a>.</p>";
    }
    else{
    ?>
    
    <?
    
    if($session->logged_in){
    ?>
    </span>
    <h1 class="style1">User Account Edit : <? echo $session->username; ?></h1>
    <span class="style1">
    <?
    if($form->num_errors > 0){
       echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
    }
    ?>
    </span>
    <form action="process.php" method="POST" class="style1">
    <table align="left" border="0" cellspacing="0" cellpadding="3">
    <tr>
    <td>Current Password:</td>
    <td><input type="password" name="curpass" maxlength="30" value="
    <?echo $form->value("curpass"); ?>"></td>
    <td><? echo $form->error("curpass"); ?></td>
    </tr>
    <tr>
    <td>New Password:</td>
    <td><input type="password" name="newpass" maxlength="30" value="
    <? echo $form->value("newpass"); ?>"></td>
    <td><? echo $form->error("newpass"); ?></td>
    </tr>
    <tr>
    <td>Email:</td>
    <td><input type="text" name="email" maxlength="50" value="
    <?
    if($form->value("email") == ""){
       echo $session->userinfo['email'];
    }else{
       echo $form->value("email");
    }
    ?>"></td>
    <td><? echo $form->error("email"); ?></td>
    </tr>
    <tr><td colspan="2" align="right">
    <input type="hidden" name="subedit" value="1">
    <input type="submit" value="Edit Account"></td></tr>
    <tr><td colspan="2" align="left"></td></tr>
    </table>
    </form>
    
    <span class="style1">
    <?
    }
    }
    
    ?>
    As you see in bold, the form is submitted to process.php

    Here is the PHP code for this form.

    Code:
       function procEditAccount(){
          global $session, $form;
    
          $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']);
    
    
          if($retval){
             $_SESSION['usersettings'] = true;
             header("Location: ".$session->referrer);
          }
    
          else{
             $_SESSION['value_array'] = $_POST;
             $_SESSION['error_array'] = $form->getErrorArray();
             header("Location: ".$session->referrer);
          }
    If there are any errors in the PHP, its because its the snippet from the entire process.php that actual matters to this particular the form. Could anyway help me make the form redirect back to the page it is submitted from! With the (?user=$session->username) on the end?

    Any help would be greatly appreciated!
    Thanks!

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    $session->referrer .= (preg_match('#\?#'$session->referrer)) ? '&user='.$session->username '?user='.$session->username;
    header("Location: ".$session->referrer); 
    OR if you want all of the URL variables carried on

    PHP Code:
    $session->referrer .= (preg_match('#\?#'$session->referrer)) ? '&'.$_SERVER['QUERY_STRING'] : '?'.$_SERVER['QUERY_STRING'] ;
    header("Location: ".$session->referrer); 
    Last edited by Mwnciau; 08-29-2007 at 12:28 AM.

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey mate, which one does what different?? and where do i add it?
    thanks

  • #4
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Use this to redirect with the user variable in the URL

    PHP Code:
    function procEditAccount(){
          global 
    $session$form;

          
    $retval $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']);


          if(
    $retval){
             
    $_SESSION['usersettings'] = true;
             
    $session->referrer .= (preg_match('#\?#'$session->referrer)) ? '&user='.$session->username '?user='.$session->username;
             
    header("Location: ".$session->referrer); 
          }

          else{
             
    $_SESSION['value_array'] = $_POST;
             
    $_SESSION['error_array'] = $form->getErrorArray();
             
    $session->referrer .= (preg_match('#\?#'$session->referrer)) ? '&user='.$session->username '?user='.$session->username;
             
    header("Location: ".$session->referrer); 
          } 

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks a lot, got it working now! cheers!


  •  

    Posting Permissions

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