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.
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 55
  1. #1
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts

    PHP login redirect to id specific page

    Hi all,

    I am building a website at the moment and would like to redirect users to a page that displays the information relating to their id when they log in. I have the login script already I just cant get it to go to the right page.

    Foster

  • #2
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    I actually resolved the above issue. I now need to make it so the user can edit the information they are seeing.

    Any help if appreciated.

    Foster

  • #3
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    620
    Thanks
    0
    Thanked 6 Times in 6 Posts
    We can't really help you with such generic information, but the basic strategy is this:

    - Store current user info in session
    - Provide a link to an edit page
    - Edit page polls database info, plugs it into existing form fields
    - User hits "Update" and the info gets pushed back into the database, where database table info user id = session user id.

  • #4
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Hi,

    Thanks for your response.

    - Store current user info in session - This I have done
    - Provide a link to an edit page - This I have done
    - Edit page polls database info, plugs it into existing form fields - This I don't know how to do!
    - User hits "Update" and the info gets pushed back into the database, where database table info user id = session user id.

    I can get the page to poll the database info and show it to the specific user but not allow them to edit it.

    Foster

  • #5
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    161
    Thanks
    37
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Foster View Post
    Hi,

    Thanks for your response.

    - Store current user info in session - This I have done
    - Provide a link to an edit page - This I have done
    - Edit page polls database info, plugs it into existing form fields - This I don't know how to do!
    - User hits "Update" and the info gets pushed back into the database, where database table info user id = session user id.

    I can get the page to poll the database info and show it to the specific user but not allow them to edit it.

    Foster
    Foster,

    If i have understood your above requirement correctly your looking for below information else ignore.

    edit page is nothing like copy your original form page in new file and name it as edit.php?edit=edit

    Now select table from db as an array, using while condition echo its value in the respective input field as VALUE (Do not change the name at any cost but just add value="" to input filed) , For example check below.

    PHP Code:
    <input type="checkbox" name="check_list" value="<? echo $row['Report ID'?>">
    do it for every input field and send back information to DB via same back end script you used while creating the record & create one if condition in back end let say if(edit=="edit") use UPDATE command else use INSERT command so, one back end script act good for create & edit data.

    but only effort you need to do is updating "VALUES" as per input types in the edit.php?edit=edit page.

    Let me know if you need any more information.

    Regards,
    Nani

  • #6
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    How would I get it to connect to my database? This is my code as it stands.

    PHP Code:
    <?php

    // Inialize session
    session_start();

    // Check, if username session is NOT set then this page will jump to login page
    if (!isset($_SESSION['Comname'])) {
    header('Location: login.html');
    }

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link href="style.css" rel="stylesheet" type="text/css" />
    <title>Imperial Army Update Form</title>
    </head>


    <body>
    <div id="container">
      <div id="header">
            
        </div>
        <div id="content">
            <div id="left">
                <div class="menu">
                    <div class="menuheader"><h3>Menu</h3></div>
                    <div class="menucontent">
                        <ul>
                            <li><a href="Impguard.html">Imperial Army Registration</a></li>
                            <li><a href="regiments.html">View Active Regiments</a></li>
                            <li><a href="igedit.html">Edit a Regiment</a></li>
                            <li><a href="ArmyGen.html">Create a Regiment</a></li>
                            <li><a href="login.html">LogIn/LogOut</a></li>
                            <li><a href="myreg.html">My Regiment</a></li>
                        </ul>
                    </div>
                    <div class="menufooter"></div>
                </div>
                
            
            
                
            </div>
            
            <div id="middle">
                <div class="post">
                    <div class="postheader">
                      <h1>Imperial Guard Army Registration</h1></div>
                    <div class="postcontent">
                        <!-- Begin Content -->
    <form action="update.php" method="post">
    <center>

    <table class="table"><tr><td background="
    " colspan="2"><font><b>Commanders Information</b></td></tr>
    <tr><td width="20%"><font>Commanders Name:&nbsp;&nbsp;&nbsp;</td>
        <td width="80%"><font><INPUT TYPE="text" NAME="Comname" size="50%" value=""></td></tr>

        <tr><td><font>Password:&nbsp;&nbsp;&nbsp;</td>
        <td><font><INPUT TYPE="password" NAME="password" size="50%" value=""></td></tr>
        <tr><td colspan="2"></td></tr>
    </table><BR><BR>

    <table class="table"><tr><td background="/~newreno/images/background2.gif" colspan="2"><font><b>Imperial Guard Regiment Information</b></td></tr>
    <tr>
        <td width="20%"><font> Regiment Name:&nbsp;&nbsp;&nbsp;</td>
        <td width="80%"><INPUT TYPE="text" NAME="name" size="50%" value="<? echo $row['name'?>"></td></tr>
    </table>
    <BR><BR>


    <BR><BR>
    <table class="table"><tr><td background="/~newreno/images/background2.gif"><center><font><b>Historical Figures</b></td></tr>
    <tr><td align="center"><TEXTAREA NAME="HistoricalFigures" ROWS="10" COLS="100" value="<? echo $row['HistoricalFigures'?>"></TEXTAREA></td></tr></table>
    <BR><BR>
    <table class="table"><tr><td background="/~newreno/images/background2.gif"><center><font><b>Notable Campaigns</b></td></tr>
    <tr><td align="center"><TEXTAREA NAME="campaigns" ROWS="10" COLS="100" value="<? echo $row['campaigns'?>">></TEXTAREA></td></tr></table>

        

    <font>
    <b>STOP!</b><br>
    Please check your information before pressing the submit button below. Looking over your information now will make sure editing later won't be necessary. Thank you.<BR>
    <input type="hidden" name="FormSubmit" value="Yes">
    <INPUT TYPE="submit" value="Update Regiment"> &nbsp; <INPUT TYPE="reset" value="Reset Fields">
    </td></tr></table>

    <!--  End Content  -->
              </div><div class="post"><div class="postcontent">
                    </div>
                    <div class="postfooter"></div>
                </div>
            </div>
        </div>
        <div id="footer">
                </div>    
    </div>
    </body>
    </html>

  • #7
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    620
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Well I can't give you a verbatim set of directions because I don't know your database schema or what you're using to access it (Native methods, an ORM, PDO, etc), but... I've tossed in some pseudo code and removed irrelevant parts and replaced them with "..."

    PHP Code:

    <?php

    // Inialize session
    session_start();

    // Check, if username session is NOT set then this page will jump to login page
    if (!isset($_SESSION['Comname'])) {
       
    header('Location: login.html');
    } else {
       
    // Get Current User ID from $_SESSION

       // query your database


       // get an array/object with appropriate values
       // e.g.
       //    $user->regiment_name = mysqlres["name"];
       //    $user->commander_name = mysqlres["CommanderName"];
       //    $user->historical = mysqlres["HistoricalFigures"];
       //    etc


       // you've got the right idea for your Regiment Name. You won't be looping 
       // through a set though (with multiple rows) because you only have a single 
       // row returned from your query
       //
       // *NB* for <TEXTAREA>, you don't set the 'value' attribute, you just put the data between the open and closing tags.

    }

    ?>
    ...

                    <div class="postcontent">
                        <!-- Begin Content -->
    <form action="update.php" method="post">
    <center>

    <table class="table"><tr><td background="
    " colspan="2"><font><b>Commanders Information</b></td></tr>
    <tr><td width="20%"><font>Commanders Name:&nbsp;&nbsp;&nbsp;</td>
        <td width="80%"><font><INPUT TYPE="text" NAME="Comname" size="50%" value="<?=$user->commander_name?>"></td></tr>

        <tr><td><font>Password:&nbsp;&nbsp;&nbsp;</td>
        <td><font><INPUT TYPE="password" NAME="password" size="50%" value=""></td></tr>
        <tr><td colspan="2"></td></tr>
    </table><BR><BR>

    <table class="table"><tr><td background="/~newreno/images/background2.gif" colspan="2"><font><b>Imperial Guard Regiment Information</b></td></tr>
    <tr>
        <td width="20%"><font> Regiment Name:&nbsp;&nbsp;&nbsp;</td>
        <td width="80%"><INPUT TYPE="text" NAME="name" size="50%" value="<?=$user->regiment_name?>"></td></tr>
    </table>
    <BR><BR>


    <BR><BR>
    <table class="table"><tr><td background="/~newreno/images/background2.gif"><center><font><b>Historical Figures</b></td></tr>
    <tr><td align="center"><TEXTAREA NAME="HistoricalFigures" ROWS="10" COLS="100"><?= $user->historical ?></TEXTAREA></td></tr></table>
    <BR><BR>
    <table class="table"><tr><td background="/~newreno/images/background2.gif"><center><font><b>Notable Campaigns</b></td></tr>
    <tr><td align="center"><TEXTAREA NAME="campaigns" ROWS="10" COLS="100" value="<? echo $row['campaigns'?>">></TEXTAREA></td></tr></table>

        

    <font>
    <b>STOP!</b><br>
    Please check your information before pressing the submit button below. Looking over your information now will make sure editing later won't be necessary. Thank you.<BR>
    <input type="hidden" name="FormSubmit" value="Yes">
    <INPUT TYPE="submit" value="Update Regiment"> &nbsp; <INPUT TYPE="reset" value="Reset Fields">
    </td></tr></table>

    <!--  End Content  -->
          ...

  • #8
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    620
    Thanks
    0
    Thanked 6 Times in 6 Posts
    then, for your update.php,
    Code:
    // Query through your form data
    // if (isset($_POST["fieldx"])) {
    //      update database
    // }
    or:
    Code:
    $myFields = array("name","regiment_name","Comname","HistoricalFigures","campaigns");
    foreach ($myFields as $field) {
       if ( (isset($_POST[$field]) && $($_POST[$field] != '') ) {
          //update database
       }
    }

  • #9
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Ok, I've got it working to populate the text box based on a specific id. I now need to do it based on the data stored from a session.

  • #10
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    in your login script try setting the page id there instead:
    PHP Code:
    $_SESSION['Username'] = $Username;
                
    setcookie("Username"$Username,time()+60*60*24*30);
                
    $_SESSION['UserID'] = $row['UserID'];
                
    $_SESSION['logged_in'] = true
    then something like

    PHP Code:

    header
    ('Location: mainpage.php?ID=' $_SESSION['UserID']); 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #11
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Hi Arcticwarrio,

    I have that already it's when selecting the database that I have the problem. The code below selects ID 1 but I want it to select according the the username of the person logged in.

    PHP Code:
    $result mysqli_query($con,"SELECT * FROM IGarmy WHERE id = 1"); 

  • #12
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    do users have an auto incremental id in the database?
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #13
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    if so it would simply be:

    PHP Code:
    $result mysqli_query($con,"SELECT * FROM IGarmy WHERE id = ".$_SESSION['UserID']); 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #14
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    What if I have it store the username in the session and not the UserID?

  • #15
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by Foster View Post
    What if I have it store the username in the session and not the UserID?
    PHP Code:
    $result mysqli_query($con,"SELECT * FROM IGarmy WHERE username = ".$_SESSION['Username']); 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  
    Page 1 of 4 123 ... LastLast

    Posting Permissions

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