Results 1 to 8 of 8

Thread: show me how to update db please

  1. #1
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default show me how to update db please

    I was wondering if someone could help me build an admin update page.

    I don't know how to even begin with this.

    I don't have many fields that I need to update but I would like to have the ability to update some information on my database.

    I have the form but I don't even know how to code this.

    All I know is I need to use the update function but I don't even know if my form is right.

    I guess what I want or how I think it should be set up is a field for me to enter the current team name and then a field for me to enter the updated name.

    anyway here is my form, have I even started doing this right?

    HTML Code:
    <form name="form2" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                  <p align="left">Old DPC Username:
                      <input name="OldUser" type="text" id="OldUser">
                      <br>
      New DPC Username:
      <input name="NewUser" type="text" id="NewUser">
      <br>
      Change username:
      <input name="UpdateUser" type="text" id="UpdateUser">
      <br>
      To Team:
      <select name="team_request" id="team_request">
          <option value="NULL" selected>Please choose a team. </option>
          <option value="Australia">Australia</option>
          <option value="Canada_I">Canada I</option>
          <option value="Canada_II">Canada II</option>
          <option value="Canada_III">Canada III</option>
          <option value="Germany">Germany</option>
          <option value="Iceland">Iceland</option>
          <option value="Islanders">Islanders</option>
          <option value="Mystery">Mystery</option>
          <option value="Poland">Poland</option>
          <option value="UK">UK</option>
          <option value="USA_Equestrian">USA Equestrian</option>
          <option value="USA_Midwest">USA Midwest</option>
          <option value="USA_Northeast">USA NorthEast</option>
          <option value="USA_Northwest">USA NorthWest</option>
          <option value="USA_Southeast">USA SouthEast</option>
          <option value="USA_Southwest">USA SouthWest</option>
      </select>
    </p>
                  <p>
                    <input type="submit" name="submit" value="Update">
    </p>
                </form>
    Last edited by Dirt_Diver; 01-23-2009 at 04:48 AM.
    ___________________________________

    Still working on it!

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Well... I would have to know your structure, but try this:

    PHP Code:
    <?php
    if(isset($_POST['submit'])){ //if the 'Update' button is pressed
      
    mysql_query("UPDATE `usernames` SET `team_request ` = '{$_POST['team_request']}' , `username` = '{$_POST['updateUser']}' WHERE `username` = '{$_POST['hidden_username']}");
    }
    ?>
    There should be another field called hidden_username that holds the username that you are editting... Change the fields and such.
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    Dirt_Diver (01-22-2009)

  4. #3
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    Actually Nile you do know my structure, I sent you a picture of it earlier this week for something else.

    And just so I can understand what is going on here what exactly is the sole purpose of the hidden username field, don't I want to put in the username so it knows who to change?
    ___________________________________

    Still working on it!

  5. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Yes. The hidden input will hold the username's name so that it knows which user to change. And I don't have the picture anymore, and I don't remember little things like a variable name or a table structure. =/
    Jeremy | jfein.net

  6. The Following User Says Thank You to Nile For This Useful Post:

    Dirt_Diver (01-22-2009)

  7. #5
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    I understand I don't remember much either...

    As for the hidden field if it's hidden how does it know which user to move? I can't tell it because it's hidden or am I missing something?

    Field | Type | Null | Default | Comments
    id | int(5) | No |
    entry_username |varchar(32) | No
    TeamCap | char(1) | No | N
    team_request | varchar(32) | No
    SeasonCount | int(1) | No | 0
    terms |char(1) | No |0
    timestamp | timestamp | No | CURRENT_TIMESTAMP
    ___________________________________

    Still working on it!

  8. #6
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    Also I adjusted the php can you tell me if it's right?

    PHP Code:
              <?php
    if(isset($_POST['submit'])){ //if the 'Update' button is pressed
      
    mysql_query("UPDATE `signups` SET `team_request` = '{$_POST['team_request']}' , `entry_username` = '{$_POST['moveuser']}' WHERE `entry_username` = '{$_POST['newuser']}");
    }
    ?>
    I also adjusted my form.
    HTML Code:
    <form name="form2" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                  <p align="left">Replace  this user:
                      <input name="OldUser" type="text" id="OldUser">
                      <br>
      With this user:
      <input name="newuser" type="text" id="newuser">
      </p>
                  <p align="left"><br>
        Move this user:
          <input name="moveuser" type="text" id="moveuser">
          <br>
        To this team:
        <select name="team_request" id="team_request">
              <option value="NULL" selected>Please choose a team. </option>
              <option value="Australia">Australia</option>
              <option value="Canada_I">Canada I</option>
              <option value="Canada_II">Canada II</option>
              <option value="Canada_III">Canada III</option>
              <option value="Germany">Germany</option>
              <option value="Iceland">Iceland</option>
              <option value="Islanders">Islanders</option>
              <option value="Mystery">Mystery</option>
              <option value="Poland">Poland</option>
              <option value="UK">UK</option>
              <option value="USA_Equestrian">USA Equestrian</option>
              <option value="USA_Midwest">USA Midwest</option>
              <option value="USA_Northeast">USA NorthEast</option>
              <option value="USA_Northwest">USA NorthWest</option>
              <option value="USA_Southeast">USA SouthEast</option>
              <option value="USA_Southwest">USA SouthWest</option>
        </select>
                  </p>
                  <p>
                    <input type="submit" name="submit" value="Update">
    </p>
                </form>
    ___________________________________

    Still working on it!

  9. #7
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No, you can't change a name where the name doesn't exist, here:

    PHP Code:
    <?php 
    if(isset($_POST['submit'])){ //if the 'Update' button is pressed 
      
    mysql_query("UPDATE `signups` SET `team_request` = '{$_POST['team_request']}' , `entry_username` = '{$_POST['moveuser']}' WHERE `entry_username` = '{$_POST['OldUser']}'"); 

    ?>
    I didn't provide validation, so you may wanna do that to. :P
    Last edited by Nile; 01-22-2009 at 01:20 AM.
    Jeremy | jfein.net

  10. The Following User Says Thank You to Nile For This Useful Post:

    Dirt_Diver (01-22-2009)

  11. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    It seems your topic is solved... Please set the status to resolved.. To do this:
    Go to your first post ->
    Edit your first post ->
    Click "Go Advanced" ->
    Then in the drop down next to the title, select "RESOLVED"
    Jeremy | jfein.net

Bookmarks

Posting Permissions

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