Adding Text to a TextArea from a variable PHP

Discussion in 'Databases' started by Sql_novice, Feb 20, 2016.

  1. #1
    <form method="POST">
    <label for="Players"> Players Team One: </label>
    <?php



    $dbuser = "draftsag_draft";
    $dbpass = "pearljam0780";
    $dbhost = "localhost";
    $db = "draftsag_sths";
    mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($db);

    $team=3;

    $sql1 = "select Name,Age,PosC,PosLW,PosRW,PosD from player WHERE Team='{$team}' ORDER BY Age";
    $query1 = mysql_query( $sql1 );

    ?>
    <select name="dynamic_data1" onchange="document.getElementById('selected_text').value=this.options[this.selectedIndex].text">>
    <?php
    $i=0;

    while($get = mysql_fetch_array($query1)) {
    ?>
    <option value="<?=$get['Name'];?>"><?=$get['Name'];?></option>
    <?php
    ++$i;

    }
    if(isset($_POST['addplayer']))
    {

    $makerValue = $_POST['dynamic_data1']; // make value

    $maker = mysql_real_escape_string($_POST['selected_text']); // get the selected text
    echo "Result:<input type='textarea' value='{$maker}'/>";
    }
    ?>
    </select>


    <input type="hidden" name="selected_text" id="selected_text" value="" />
    <input type="submit" name="addplayer" value="Add a Player"/>
    </form>


    <form method="POST">
    <label for="Players"> Players Team Two: </label>
    <?php



    $dbuser = "draftsag_draft";
    $dbpass = "pearljam0780";
    $dbhost = "localhost";
    $db = "draftsag_sths";
    mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($db);

    $team=3;

    $sql2 = "select Name,Age,PosC,PosLW,PosRW,PosD from player WHERE Team='{$team}' ORDER BY Age";
    $query2 = mysql_query( $sql2 );

    ?>
    <select name="dynamic_data2" onchange="document.getElementById('selected_text').value=this.options[this.selectedIndex].text">>
    <?php
    $i=0;

    while($get = mysql_fetch_array($query2)) {
    ?>
    <option value="<?=$get['Name'];?>"><?=$get['Name'];?></option>
    <?php
    ++$i;

    }
    if(isset($_POST['search']))
    {

    $makerValue = $_POST['dynamic_data2']; // make value

    $player = mysql_real_escape_string($_POST['selected_text']); // get the selected text
    echo "Result:<input type='textarea' value='{$player}'/>";
    }
    ?>
    </select>


    <input type="hidden" name="selected_text" id="selected_text" value="" />
    <input type="submit" name="search" value="Add a Player"/>
    </form>

    first part is exactly the same as the second part except the name attribute is changed

    the first part works as in outputting text to the textarea however the second part is not working

    any help would be appreciated

    thanks
     
    Sql_novice, Feb 20, 2016 IP
  2. Sql_novice

    Sql_novice Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    fixed this code
     
    Sql_novice, Feb 20, 2016 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    You probably didn't, though. That code is horrible. Really, really bad. I get that you're just starting out, but... wow. Whereever you're learning what you're doing, I suggest you toss it, and start over. There are multiple issues with the code, formatting, mixing inline-javascript, using mysql_-db-connection, using variables in queries...

    As for the solution you found, I guess it has something to do with multiple same IDs (only ONE of each ID per page)? It's common curtesy to put down the solution when you find it yourself, to benefit others. It's also smart to use [ code ]-blocks around code (or just use the insert-button in the editor.
     
    PoPSiCLe, Feb 21, 2016 IP