Help in inserting age into table

Discussion in 'MySQL' started by ScottDB, Jun 15, 2011.

  1. #1
    Hi, I am following a tutorial about how to add an age profile to my script. At the end it says "now for the sql, whcih you proberly know what to do, so i won't tell you that".

    The table I would like it to be placed in is called users.

    INSERT INTO users age (
    what
    );
     
    Last edited: Jun 15, 2011
    ScottDB, Jun 15, 2011 IP
  2. ScottDB

    ScottDB Greenhorn

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    Ok I tried it about every way I could and could not get this to work. Kept getting errors every time I tried to insert this into my db. Could you tell me the exact sql to insert this into my table?
     
    ScottDB, Jun 16, 2011 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    jestep, Jun 16, 2011 IP
  4. ScottDB

    ScottDB Greenhorn

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    I tried that but I get the error message when submitting it. "#1054 - Unknown column 'age' in 'field list'"
     
    ScottDB, Jun 16, 2011 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    Can you post the structure of the users table?
     
    jestep, Jun 16, 2011 IP
  6. ScottDB

    ScottDB Greenhorn

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #6
    Thanks for the response. I figured it would probably depend on how I have it set up. Forgive me but I am really new to sql and php. Here is the code in the tutorial for how to add this to my script. I've already edited the pages which I know enough about php to do just don't know how to make the sql for it.
    
    
    hers an example of how to do it, lets say you wanted to add an age input box heres what you would do in useredit.php 
     <tr>
    <td>Age:</td>
    <td><input type="text" name="age" maxlength="25" value="
    <?
    if($form->value("age") == ""){
       echo $session->userinfo['age'];
    }else{
       echo $form->value("age");
    }
    ?>"></td>
    <td><? echo $form->error("age"); ?></td>
    </tr>
    
    
    it's pretty easy to see where you would put it and then in userinfo.php 
    
    
    /* Age */
    echo "<b>Age:</b> ".$req_user_info['age']."<br>";
    looks easy so far doesn't it? okay now for process.php 
    /**
        * procEditAccount - Attempts to edit the user's account
        * information, including the password, which must be verified
        * before a change is made.
        */
       function procEditAccount(){
          global $session, $form;
          /* Account edit attempt */
          $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email'], $_POST['age'],);
    
          
          that part is easy, just adding one thing thats all then last but not least go to session.php in the include folder okay first off scroll down till you see 
    
          
          /**
        * editAccount - Attempts to edit the user's account information
        * including the password, which it first makes sure is correct
        * if entered, if so and the new password is in the right
        * format, the change is made. All other fields are changed
        * automatically.*/
       function editAccount($subcurpass, $subnewpass, $subemail, $subage){
    
       soemthing liek that, then add $subwhatever at the end like shown above. then you need to scroll down further then after where it says change email add the following lines, or similar to what you need. 
    
       /* age */
          if($subage){
             $database->updateUserField($this->username,"age",$subage);
    
    Code (markup):
     
    ScottDB, Jun 16, 2011 IP
  7. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #7
    I'd question any tutorial that would have you create an 'age' field. It's a calculated value and shouldn't be stored in a database. Instead you should store the birthdate and calculate age whenever you need that data.
     
    plog, Jun 20, 2011 IP
  8. ScottDB

    ScottDB Greenhorn

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #8
    That would be good as well. The reason why I was trying to do age instead of birthdate is that I thought it would be easier for a newbie to do. If you could tell me how to add birthdate it would be very much appreciated.
     
    ScottDB, Jun 20, 2011 IP