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 9 of 9
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    After Password Protection...

    Hello,
    I have set up my password protection and logins and it redirects the user to their own page. I want users to edit their own profiles on the site and for them to post news.
    How do I go about doing this! Please make it easy!

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When the user logs in set a session var for the username and/or userid.
    Create a update profile page and in the query select WHERE userid = $_SESSION['userid'];

    This will make it so that the logged in user loads their own page.

    Then output the recordset into form vars and have a simple update script with validation.

    http://www.zend.com/php/beginners/php101-8.php#Heading6
    http://www.w3schools.com/sql/sql_update.asp

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [QUOTE=degsy]
    Then output the recordset into form vars and have a simple update script with validation.
    QUOTE]
    How do i make a var and how do i make the update script?

  • #4
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This is a basic system that is used on on the admin's side of a site. You will need to change the input boxes & MySQL field names to match your site.

    PHP Code:
    <?php
        
    if(isset($_POST['save']))
            {
                
    $id $_SESSION['userid'];
                
    $customers_firstname $_POST['customers_firstname'];
                
    $customers_lastname $_POST['customers_lastname'];
                
    $customers_email $_POST['customers_email'];
                
    $customers_email $_POST['customers_email'];
                
    $customers_street_address $_POST['customers_street_address'];
                
    $customers_city $_POST['customers_city'];
                
    $customers_postcode $_POST['customers_postcode'];
                
    $customers_state $_POST['customers_state'];
                
    $customers_country $_POST['customers_country'];
                
    $customers_phone $_POST['customers_phone'];
                
    $customers_email_address $_POST['customers_email_address'];
                
    $customers_phone2 $_POST['customers_phone2'];
                
    $customers_username $_POST['customers_username'];
                
    $account_created $_POST['customers_date_account_created'];
                
    $now date("Y-m-d H:i:s");
            
                
    $update_customer = ("UPDATE $customer_table SET customers_firstname = '$customers_firstname', 
                customers_lastname = '$customers_lastname', customers_email = '$customers_email', 
                customers_street_address = '$customers_street_address', customers_city = '$customers_city', 
                customers_postcode = '$customers_postcode', customers_state = '$customers_state', 
                customers_country = '$customers_country', customers_phone = '$customers_phone', 
                customers_phone2 = '$customers_phone2', customers_username = '$customers_username',
                customers_date_account_last_modified = '$now', customers_date_account_created = '$account_created' 
                WHERE customers_id = '$id'"
    );
                
    $update_query mysql_query($update_customer) or die(mysql_error());
            
                if(!
    $update_query)
                {
                    echo 
    'Error in updating customer contact information!';
                }
                else
                {
                    echo 
    'Customer contact information successfully updated!';
                }
            }
        else
            {
                
    $id $_SESSION['userid']; 
                
    $order_details mysql_query("SELECT * FROM customers WHERE customers_id= '$id' ");
                while (
    $line mysql_fetch_array($order_details)) {
                
    $customers_id $line["customers_id"];
                
    $customers_firstname $line["customers_firstname"];
                
    $customers_lastname $line["customers_lastname"];
                
    $customers_email stripslashes($line["customers_email"]);
                
    $customers_street_address $line["customers_street_address"];
                
    $customers_city $line["customers_city"];
                
    $customers_postcode $line["customers_postcode"];
                
    $customers_state $line["customers_state"];
                
    $customers_country $line["customers_country"];
                
    $customers_phone $line["customers_phone"];
                
    $customers_phone2 $line["customers_phone2"];
                
    $customers_username $line["customers_username"];
                
    $customers_ip $line["customers_ip"];
                
    //$customers_date_of_last_logon = date("m-d-Y h:i:s A", strtotime($line['customers_date_of_last_logon']));
                
    $customers_number_of_logons $line["customers_number_of_logons"];
                
    $customers_date_account_created date("m-d-Y h:i:s A"strtotime($line['customers_date_account_created']));
                
    $customers_date_account_last_modified date("m-d-Y h:i:s A"strtotime($line['customers_date_account_last_modified']));
                echo
    '';
            } 
        
    ?>

    <form action="<?php $_SERVER['PHP_SELF'?>" method="post" name="customer_details" id="customer_details">
      <table width="50%" border="0" align="center" class="newsheader">
        <caption>
      Customer Details for ID <strong><?=$customers_id ?></strong>
      
        </caption>
        <tr>
          <td width="21%"><div align="right">First Name:</div></td>
          <td width="40%"><input name="customers_firstname" type="text" id="customers_firstname" value="<?=$customers_firstname ?>"></td>
          <td width="21%"><div align="right">E-Mail:</div></td>
          <td width="40%"><input name="customers_email" type="text" id="customers_email" value="<?=$customers_email ?>"></td>
        </tr>
        <tr>
          <td><div align="right">Last Name: </div></td>
          <td><input name="customers_lastname" type="text" id="customers_lastname" value="<?=$customers_lastname ?>"></td>
          <td><div align="right">User Name: </div></td>
          <td><input name="customers_username" type="text" id="customers_username" value="<?=$customers_username ?>"></td>
        </tr>
        <tr>
          <td><div align="right">Street:</div></td>
          <td><input name="customers_street_address" type="text" id="customers_street_address" value="<?=$customers_street_address ?>"></td>
          <td><div align="right">City:</div></td>
          <td><input name="customers_city" type="text" id="customers_city" value="<?=$customers_city ?>"></td>
        </tr>
        <tr>
          <td><div align="right">State:</div></td>
          <td><input name="customers_state" type="text" id="customers_state" value="<?=$customers_state ?>"></td>
          <td><div align="right">Zip:</div></td>
          <td><input name="customers_postcode" type="text" id="customers_postcode" value="<?=$customers_postcode ?>"></td>
        </tr>
        <tr>
          <td><div align="right">Phone:</div></td>
          <td><input name="customers_phone" type="text" id="customers_phone" value="<?=$customers_phone ?>"></td>
          <td><div align="right">Mobile:</div></td>
          <td><input name="customers_phone2" type="text" id="customers_phone2" value="<?=$customers_phone2 ?>"></td>
        </tr>
        <tr>
          <td><div align="right">IP:</div></td>
          <td><?=$customers_ip ?></td>
          <td><div align="right">Last Login: </div></td>
          <td><?=$customers_date_of_last_logon ?></td>
        </tr>
        <tr>
          <td><div align="right">Created:</div></td>
          <td><input name="customers_date_account_created" type="text" id="customers_date_account_created" value="<?=$customers_date_account_created ?>"></td>
          <td><div align="right">Modified:</div></td>
          <td><?=$customers_date_account_last_modified ?></td>
        </tr>
        <tr>
          <td colspan="4"><div align="center">
            <input name="save" type="submit" id="save" value="Save">
          </div></td>
        </tr>
      </table>
    </form>
        <?
        
    }
        
    ?>

  • #5
    New Coder
    Join Date
    May 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how do i link that php script to a update and edit button?

  • #6
    New Coder
    Join Date
    May 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts
    after the script that is above. i need some way of linking that information to a table so you can litterally edit save then view. please help!

  • #7
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey can you guys create for me a portal system? I mean for free and all... I would be all to happy to thank you
    Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

  • #8
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ainsleyclark
    how do i link that php script to a update and edit button?
    I have a page that displays all users & I have the user's ID # a link to the edit form below. Then on the form the update button would be save changes.


    Quote Originally Posted by ainsleyclark
    after the script that is above. i need some way of linking that information to a table so you can litterally edit save then view. please help!
    It will just be a simple modification to my script above. If this is for the user themselves to modify their information the use the script as I have it below. If you are modifiying it on the admin site, then just change the $id = $_SESSION['userid']; to $id = $_GET['userid']; & delet this from the header Location line ?userid= ' . $id . '. You need to make those changes because you are probly clicking on the user name or id number in a list of your users right? If it is the user then you need to pull the user id from a cookie that you should have already set & if the user is changing it then you don't need to be tring to pull userid from a URL when it is in a session.


    If when you first try to edit the user or the user first tried to edit their information & click the save button a couple of things will happen. The user or you will see that the inforamtion was updated or not updated, but you will also be directed back to the file that displays the form to edit the user's info.
    PHP Code:
    <?php
        
    if(isset($_POST['save']))
            {
                
    $id $_SESSION['userid'];
                
    $customers_firstname $_POST['customers_firstname'];
                
    $customers_lastname $_POST['customers_lastname'];
                
    $customers_email $_POST['customers_email'];
                
    $customers_email $_POST['customers_email'];
                
    $customers_street_address $_POST['customers_street_address'];
                
    $customers_city $_POST['customers_city'];
                
    $customers_postcode $_POST['customers_postcode'];
                
    $customers_state $_POST['customers_state'];
                
    $customers_country $_POST['customers_country'];
                
    $customers_phone $_POST['customers_phone'];
                
    $customers_email_address $_POST['customers_email_address'];
                
    $customers_phone2 $_POST['customers_phone2'];
                
    $customers_username $_POST['customers_username'];
                
    $account_created $_POST['customers_date_account_created'];
                
    $now date("Y-m-d H:i:s");
            
                
    $update_customer = ("UPDATE $customer_table SET customers_firstname = '$customers_firstname', 
                customers_lastname = '$customers_lastname', customers_email = '$customers_email', 
                customers_street_address = '$customers_street_address', customers_city = '$customers_city', 
                customers_postcode = '$customers_postcode', customers_state = '$customers_state', 
                customers_country = '$customers_country', customers_phone = '$customers_phone', 
                customers_phone2 = '$customers_phone2', customers_username = '$customers_username',
                customers_date_account_last_modified = '$now', customers_date_account_created = '$account_created' 
                WHERE customers_id = '$id'"
    );
                
    $update_query mysql_query($update_customer) or die(mysql_error());
            
                if(!
    $update_query)
                {
                    echo 
    'Error in updating customer contact information!';
                    
    header("Location: ' . $_SERVER['PHP_SELF'] . '?userid= ' . $id . ' ");

                }
                else
                {
                    echo 
    'Customer contact information successfully updated!';
                    
    header("Location: ' . $_SERVER['PHP_SELF'] . '?userid= ' . $id . ' ");
                }
            }
        else
            {
                
    $id $_SESSION['userid']; 
                
    $order_details mysql_query("SELECT * FROM customers WHERE customers_id= '$id' ");
                while (
    $line mysql_fetch_array($order_details)) {
                
    $customers_id $line["customers_id"];
                
    $customers_firstname $line["customers_firstname"];
                
    $customers_lastname $line["customers_lastname"];
                
    $customers_email stripslashes($line["customers_email"]);
                
    $customers_street_address $line["customers_street_address"];
                
    $customers_city $line["customers_city"];
                
    $customers_postcode $line["customers_postcode"];
                
    $customers_state $line["customers_state"];
                
    $customers_country $line["customers_country"];
                
    $customers_phone $line["customers_phone"];
                
    $customers_phone2 $line["customers_phone2"];
                
    $customers_username $line["customers_username"];
                
    $customers_ip $line["customers_ip"];
                
    //$customers_date_of_last_logon = date("m-d-Y h:i:s A", strtotime($line['customers_date_of_last_logon']));
                
    $customers_number_of_logons $line["customers_number_of_logons"];
                
    $customers_date_account_created date("m-d-Y h:i:s A"strtotime($line['customers_date_account_created']));
                
    $customers_date_account_last_modified date("m-d-Y h:i:s A"strtotime($line['customers_date_account_last_modified']));
                echo
    '';
            } 
        
    ?>

    <form action="<?php $_SERVER['PHP_SELF'?>" method="post" name="customer_details" id="customer_details">
      <table width="50%" border="0" align="center" class="newsheader">
        <caption>
      Customer Details for ID <strong><?=$customers_id ?></strong>
      
        </caption>
        <tr>
          <td width="21%"><div align="right">First Name:</div></td>
          <td width="40%"><input name="customers_firstname" type="text" id="customers_firstname" value="<?=$customers_firstname ?>"></td>
          <td width="21%"><div align="right">E-Mail:</div></td>
          <td width="40%"><input name="customers_email" type="text" id="customers_email" value="<?=$customers_email ?>"></td>
        </tr>
        <tr>
          <td><div align="right">Last Name: </div></td>
          <td><input name="customers_lastname" type="text" id="customers_lastname" value="<?=$customers_lastname ?>"></td>
          <td><div align="right">User Name: </div></td>
          <td><input name="customers_username" type="text" id="customers_username" value="<?=$customers_username ?>"></td>
        </tr>
        <tr>
          <td><div align="right">Street:</div></td>
          <td><input name="customers_street_address" type="text" id="customers_street_address" value="<?=$customers_street_address ?>"></td>
          <td><div align="right">City:</div></td>
          <td><input name="customers_city" type="text" id="customers_city" value="<?=$customers_city ?>"></td>
        </tr>
        <tr>
          <td><div align="right">State:</div></td>
          <td><input name="customers_state" type="text" id="customers_state" value="<?=$customers_state ?>"></td>
          <td><div align="right">Zip:</div></td>
          <td><input name="customers_postcode" type="text" id="customers_postcode" value="<?=$customers_postcode ?>"></td>
        </tr>
        <tr>
          <td><div align="right">Phone:</div></td>
          <td><input name="customers_phone" type="text" id="customers_phone" value="<?=$customers_phone ?>"></td>
          <td><div align="right">Mobile:</div></td>
          <td><input name="customers_phone2" type="text" id="customers_phone2" value="<?=$customers_phone2 ?>"></td>
        </tr>
        <tr>
          <td><div align="right">IP:</div></td>
          <td><?=$customers_ip ?></td>
          <td><div align="right">Last Login: </div></td>
          <td><?=$customers_date_of_last_logon ?></td>
        </tr>
        <tr>
          <td><div align="right">Created:</div></td>
          <td><input name="customers_date_account_created" type="text" id="customers_date_account_created" value="<?=$customers_date_account_created ?>"></td>
          <td><div align="right">Modified:</div></td>
          <td><?=$customers_date_account_last_modified ?></td>
        </tr>
        <tr>
          <td colspan="4"><div align="center">
            <input name="save" type="submit" id="save" value="Save">
          </div></td>
        </tr>
      </table>
    </form>
        <?
        
    }
        
    ?>

  • #9
    New Coder
    Join Date
    May 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think i have that sorted in my brain. Is there anything else I need to do in order for the user to save their information and then for guest to view it? And also the script you gave, when the user clicks the save button where is it redirecting them to?
    Oh and yep there is an ID for each user and this is directing them to their php (1.php, 2.php).


  •  

    Posting Permissions

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