SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    updating info, need <select> help

    Ok If all goes well I'll be able to stop asking questions everyday.

    Here's what I have so far. I have a page to enter in information, in that page some of the info is in select menus.

    Now I'm making a page to update the stored information. Instead of having to re-select the option that was chosen before, How would I make the menu show the option that was assigned to it before?

    The way the information is put into the database is it takes whatever the value of the list was and stores it as text. (If that's the way it always is you'll have to excuse my newbieness )

    For example, If the menu was setup like this:

    <select name="playercharactor" size="1">
    <option selected>Choose Charactor</option>
    <option value="Sniper">Sniper</option>
    <option value="Gunner">Gunner</option>
    <option value="Aquadic Medic">Aquadic Medic</option>
    <option value="Granadier">Granadier</option>
    <option value="Close Quarters Combat">Close Quarters Combat</option>
    </select>

    And the entry sected was "Sniper" then in the database if you view the entry it would just say "Sniper."

    How can I make the menu show "Sniper" as sected when I load their profile to edit it?
    You smell something?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll need to check the value of $playercharactor on each element you want to have in the drop down.


    NOTE: This code assumes the variable $playercharactor is populated from the database.

    PHP Code:
    <select name="playercharactor" size="1"> 
    <option<?=(!$playercharactor) ? " selected" ""?>>Choose Charactor</option> 
    <option value="Sniper"<?=($playercharactor == "Sniper") ? " selected" ""?>>Sniper</option> 
    <option value="Gunner"<?=($playercharactor == "Gunner") ? " selected" ""?>>Gunner</option> 
    <option value="Aquadic Medic"<?=($playercharactor == "Aquadic Medic") ? " selected" ""?>>Aquadic Medic</option> 
    <option value="Granadier"<?=($playercharactor == "Granadier") ? " selected" ""?>>Granadier</option> 
    <option value="Close Quarters Combat"<?=($playercharactor == "Close Quarters Combat") ? " selected" ""?>>Close Quarters Combat</option> 
    </select>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No dice, it didn't work.

    Here's my code including the part you gave me from the example:
    PHP Code:
    <?php

    /************************************************************************/
    /* PHP-NUKE: Web Portal System                                          */
    /* ===========================                                          */
    /*                                                                      */
    /* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
    /* h*tp://phpnuke.org                                                   */
    /*                                                                      */
    /* This program is free software. You can redistribute it and/or modify */
    /* it under the terms of the GNU General Public License as published by */
    /* the Free Software Foundation; either version 2 of the License.       */
    /************************************************************************/

    if(!isset($mainfile)) { include("mainfile.php"); }
    include(
    "header.php");

    $result mysql_query("SELECT
        playerrealname,location,playerjob,playercharactor,playerquote,playerstatus,
        playerweapons,playerpicture,playername,playerpoints,playerrank,playerdevision
            FROM player_profile WHERE playername='
    $playername'");
        list(
            
    $playerrealname,$location,$playerjob,$playercharactor,$playerquote,$playerstatus,
            
    $playerweapons,$playerpicture,$playername,$playerpoints,$playerrank,$playerdevision)
        = 
    mysql_fetch_row($result);

      

    if (
    "Update" == $update) { 
        
    $sql "UPDATE player_profile WHERE playername='$playername' VALUES(" 
        
    "'$playerrealname', " 
        
    "'$location', " 
        
    "'$playerjob', " 
        
    "'$playercharactor', " 
        
    "'$playerquote', " 
        
    "'$playerstatus', " 
        
    "'$playerweapons', " 
        
    "'$playerpicture', " 
        
    "'$playername', " 
        
    "'$playerpoints', " 
        
    "'$playerrank', " 
        
    "'$playerdevision')";
        
    if (
    mysql_query($sql)) {
        echo(
    "<P>Your profile has been updated.</P>"); 
        } else {
        echo(
    "<P>Error updating profile: " 
        
    mysql_error() . "</P>"); }}
    ?>



    <FORM ACTION="<?php echo($PHP_SELF); ?>"  METHOD="POST">
      <table width="99%" border="1" cellspacing="0" cellpadding="3" bordercolor="#003300">
        <tr bgcolor="#003300"> 
          <td colspan="2"><b>Update A Players Profile</b> </td>
        </tr>
        <tr> 
          <td width="150" align="right"> Real Name:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playerrealname); ?>" name="playerrealname" size=30 MAXLENGTH=30>
            Max charactors (30) </td>
        </tr>
        <tr> 
          <td width="150" align="right">Game Name: </td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playername); ?>" name="playername" size=30 MAXLENGTH=30>
            Max charactors (30) </td>
        </tr>
        <tr> 
          <td width="150" align="right">Location:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($location); ?>" name="location" size=30 MAXLENGTH=40>
            Max charactors (40) </td>
        </tr>
        <tr> 
          <td width="150" align="right">Job:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playerjob); ?>" name="playerjob" size=30 MAXLENGTH=30>
            Max charactors (30) </td>
        </tr>
        <tr> 
          <td width="150" align="right">Picture:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playerpicture); ?>" name="playerpicture" size=30 MAXLENGTH=100>
            &lt;= Not yet in use.</td>
        </tr>
        <tr> 
          <td width="150" align="right">charactor:</td>
          <td> 
            <select name="playercharactor" size="1"> 
                <option<?=(!$playercharactor) ? " selected" ""?>>Choose Charactor</option> 
                <option value="Sniper"<?=($playercharactor == "Sniper") ? " selected" ""?>>Sniper</option> 
                <option value="Gunner"<?=($playercharactor == "Gunner") ? " selected" ""?>>Gunner</option> 
                <option value="Aquadic Medic"<?=($playercharactor == "Aquadic Medic") ? " selected" ""?>>Aquadic Medic</option> 
                <option value="Granadier"<?=($playercharactor == "Granadier") ? " selected" ""?>>Granadier</option> 
            <option value="Close Quarters Combat"<?=($playercharactor == "Close Quarters Combat") ? " selected" ""?>>Close Quarters Combat</option> 
    </select> 
          </td>
        </tr>
        <tr> 
          <td width="150" align="right">Quote: </td>
          <td> 
            <textarea class="input" name="playerquote" cols="40 MAXLENGTH=100" rows="5"><? echo ($playerquote); ?></textarea>
            Max charactors (100)</td>
        </tr>
        <tr> 
          <td width="150" align="right">Weapons:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playerweapons); ?>" name="playerweapons" size=30 MAXLENGTH=40>
            Max charactors (40) </td>
        </tr>
        <tr> 
          <td width="150" align="right">Status:</td>
          <td> 
            <select name="playerstatus" size="1">
              <option value="Active" selected>Active</option>
              <option value="Inactive">Inactive</option>
            </select>
          </td>
        </tr>
        <tr> 
          <td width="150" align="right">Points:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playerpoints); ?>" name="playerpoints" size=30 MAXLENGTH=5>
            Max charactors (5) <font size="1">(That's up to 99.999 points can be earned, 
            who'd need more?) </font></td>
        </tr>
        <tr> 
          <td width="150" align="right">Rank:</td>
          <td>
            <select name="playerrank" size="1">
              <option selected>Choose a Rank</option>
              <option value="New Recruit">New Recruit</option>
              <option value="Private">Private</option>
              <option value="Corporal">Corporal</option>
              <option value="Sergeant">Sergeant</option>
              <option value="Master Sergeant">Master Sergeant</option>
              <option value="Command Sergeant Major">Command Sergeant Major</option>
              <option value="2nd Lieutenant">2nd Lieutenant</option>
              <option value="1st  Lieutenant">1st Lieutenant</option>
              <option value="Captain">Captain</option>
              <option value="Colonel">Colonel</option>
              <option value="1 Star General">1 Star General</option>
              <option value="2 Star General">2 Star General</option>
              <option value="3 Star General">3 Star General</option>
              <option value="4 Star General">4 Star General</option>
              <option value="5 Star General">5 Star General</option>
            </select>
          </td>
        </tr>
        <tr> 
          <td width="150" align="right">Devision: </td>
          <td> 
            <select name="playerdevision" size="1">
              <option selected>Choose a devision</option>
              <option value="Alpha">Alpha</option>
              <option value="Bravo">Bravo</option>
              <option value="Charlie">Charlie</option>
            </select>
          </td>
        </tr>
        <tr bgcolor="#003300" align="center"> 
          <td colspan="2">ALL Feilds are necessary, make sure you've left nothing 
            blank. If some info is unknown type &quot;N/A&quot; or process may fail!</td>
        </tr>
        <tr bgcolor="#003300"> 
          <td width="150" align="right">&nbsp;</td>
          <td> 
            <input type="submit" name="update" value="Update">
            <input type="hidden" name="playername" value="<?=$playername?>">
          </td>
        </tr>
      </table>
    </FORM>
    <?php include("footer.php"); ?>
    You smell something?

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its not working right? Or you are not using it right? I know it is working cause Ijust tested it. One thing if you are updating and not seeing the new data, try moving the queries around. Move the initial select statement down below the update clause. Let me show you how to grab all the data from the table and assign the variables a little better.

    PHP Code:

    <?php

    /************************************************************************/
    /* PHP-NUKE: Web Portal System                                          */
    /* ===========================                                          */
    /*                                                                      */
    /* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
    /* h*tp://phpnuke.org                                                   */
    /*                                                                      */
    /* This program is free software. You can redistribute it and/or modify */
    /* it under the terms of the GNU General Public License as published by */
    /* the Free Software Foundation; either version 2 of the License.       */
    /************************************************************************/

    if(!isset($mainfile)) { include("mainfile.php"); }
    include(
    "header.php");

      

    if (
    "Update" == $update) { 
        
    $sql "UPDATE player_profile set 
        playerrealname = '
    $playerrealname', 
        location = '
    $location', 
        playerjob = '
    $playerjob', 
        playercharactor = '
    $playercharactor', 
        playerquote = '
    $playerquote',  
        playerstatus = '
    $playerstatus',  
        playerweapons = '
    $playerweapons', 
        playerpicture = '
    $playerpicture', 
        playername = '
    $playername',  
        playerpoints = '
    $playerpoints', 
        playerrank = '
    $playerrank', 
        playerdivision = '
    $playerdevision
        WHERE playername='
    $playername'
        "
    ;
        
    if (
    mysql_query($sql)) {
        echo(
    "<P>Your profile has been updated.</P>"); 
        } else {
        echo(
    "<P>Error updating profile: "mysql_error() . "</P>"); }}


    $result mysql_query("SELECT * FROM player_profile WHERE playername='$playername'");
    $row mysql_fetch_array($result);
    extract($row);
    /*
    Old way
    $result = mysql_query("SELECT
        playerrealname,location,playerjob,playercharactor,playerquote,playerstatus,
        playerweapons,playerpicture,playername,playerpoints,playerrank,playerdevision
            FROM player_profile WHERE playername='$playername'");
        list(
            $playerrealname,$location,$playerjob,$playercharactor,$playerquote,$playerstatus,
            $playerweapons,$playerpicture,$playername,$playerpoints,$playerrank,$playerdevision)
        = mysql_fetch_row($result);
    */

    ?>



    <FORM ACTION="<?php echo($PHP_SELF); ?>"  METHOD="POST">
      <table width="99%" border="1" cellspacing="0" cellpadding="3" bordercolor="#003300">
        <tr bgcolor="#003300"> 
          <td colspan="2"><b>Update A Players Profile</b> </td>
        </tr>
        <tr> 
          <td width="150" align="right"> Real Name:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playerrealname); ?>" name="playerrealname" size=30 MAXLENGTH=30>
            Max charactors (30) </td>
        </tr>
        <tr> 
          <td width="150" align="right">Game Name: </td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playername); ?>" name="playername" size=30 MAXLENGTH=30>
            Max charactors (30) </td>
        </tr>
        <tr> 
          <td width="150" align="right">Location:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($location); ?>" name="location" size=30 MAXLENGTH=40>
            Max charactors (40) </td>
        </tr>
        <tr> 
          <td width="150" align="right">Job:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playerjob); ?>" name="playerjob" size=30 MAXLENGTH=30>
            Max charactors (30) </td>
        </tr>
        <tr> 
          <td width="150" align="right">Picture:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playerpicture); ?>" name="playerpicture" size=30 MAXLENGTH=100>
            &lt;= Not yet in use.</td>
        </tr>
        <tr> 
          <td width="150" align="right">charactor:</td>
          <td> 
            <select name="playercharactor" size="1"> 
                <option<?=(!$playercharactor) ? " selected" ""?>>Choose Charactor</option> 
                <option value="Sniper"<?=($playercharactor == "Sniper") ? " selected" ""?>>Sniper</option> 
                <option value="Gunner"<?=($playercharactor == "Gunner") ? " selected" ""?>>Gunner</option> 
                <option value="Aquadic Medic"<?=($playercharactor == "Aquadic Medic") ? " selected" ""?>>Aquadic Medic</option> 
                <option value="Granadier"<?=($playercharactor == "Granadier") ? " selected" ""?>>Granadier</option> 
            <option value="Close Quarters Combat"<?=($playercharactor == "Close Quarters Combat") ? " selected" ""?>>Close Quarters Combat</option> 
    </select> 
          </td>
        </tr>
        <tr> 
          <td width="150" align="right">Quote: </td>
          <td> 
            <textarea class="input" name="playerquote" cols="40 MAXLENGTH=100" rows="5"><? echo ($playerquote); ?></textarea>
            Max charactors (100)</td>
        </tr>
        <tr> 
          <td width="150" align="right">Weapons:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playerweapons); ?>" name="playerweapons" size=30 MAXLENGTH=40>
            Max charactors (40) </td>
        </tr>
        <tr> 
          <td width="150" align="right">Status:</td>
          <td> 
            <select name="playerstatus" size="1">
              <option value="Active" selected>Active</option>
              <option value="Inactive">Inactive</option>
            </select>
          </td>
        </tr>
        <tr> 
          <td width="150" align="right">Points:</td>
          <td> 
            <input class=input type="TEXT" value="<? echo ($playerpoints); ?>" name="playerpoints" size=30 MAXLENGTH=5>
            Max charactors (5) <font size="1">(That's up to 99.999 points can be earned, 
            who'd need more?) </font></td>
        </tr>
        <tr> 
          <td width="150" align="right">Rank:</td>
          <td>
            <select name="playerrank" size="1">
              <option selected>Choose a Rank</option>
              <option value="New Recruit">New Recruit</option>
              <option value="Private">Private</option>
              <option value="Corporal">Corporal</option>
              <option value="Sergeant">Sergeant</option>
              <option value="Master Sergeant">Master Sergeant</option>
              <option value="Command Sergeant Major">Command Sergeant Major</option>
              <option value="2nd Lieutenant">2nd Lieutenant</option>
              <option value="1st  Lieutenant">1st Lieutenant</option>
              <option value="Captain">Captain</option>
              <option value="Colonel">Colonel</option>
              <option value="1 Star General">1 Star General</option>
              <option value="2 Star General">2 Star General</option>
              <option value="3 Star General">3 Star General</option>
              <option value="4 Star General">4 Star General</option>
              <option value="5 Star General">5 Star General</option>
            </select>
          </td>
        </tr>
        <tr> 
          <td width="150" align="right">Devision: </td>
          <td> 
            <select name="playerdevision" size="1">
              <option selected>Choose a devision</option>
              <option value="Alpha">Alpha</option>
              <option value="Bravo">Bravo</option>
              <option value="Charlie">Charlie</option>
            </select>
          </td>
        </tr>
        <tr bgcolor="#003300" align="center"> 
          <td colspan="2">ALL Feilds are necessary, make sure you've left nothing 
            blank. If some info is unknown type &quot;N/A&quot; or process may fail!</td>
        </tr>
        <tr bgcolor="#003300"> 
          <td width="150" align="right">&nbsp;</td>
          <td> 
            <input type="submit" name="update" value="Update">
            <input type="hidden" name="playername" value="<?=$playername?>">
          </td>
        </tr>
      </table>
    </FORM>
    <?php include("footer.php"); ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, I checked it out & it's working now.

    Store this thread under stupid newbie tricks lol

    Here's what happened, when I was making the add player to roster page I didn't have the dropdown menus for those fields(they were text fields then ) And I was entering dummy info to test it out.

    In the test to get the dropdown menus It couldn't find the right one to make "Selected" because the text didn't match the criteria. The dummy info was different.

    Thanks again for your help man, you solved 2 of my problems in one day!

    P.S. Say hi to your cat for me

    <usless info> I've got a dog about 15 yrs. old, we're gonna have to take her to the vet. in about 2 days. She's got a weird growth on her ear. My mom thinks she may have to be "put down" She is pretty old. </usless info>
    You smell something?


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
  •