Jump to content
×
×
  • Create New...
  • 0

PHP - insert $ into a <select><option></option></select>


ReFresh

Question

Hi guys,

I'm searching solution for my code. I need to include character names which account contain from database to <select> and <option> tag. Then I need to do button which will debug selected character name from created (select and option) dropdown "menu".

There's my code:

http://pastebin.com/nWP5Vtgy

I will be glad if someone can help me.

There's example how it will looks:

vysledek_20170208_213201.jpg

PS: I know, I'm using old PHP version.

Thanks for answers!

Sincerely,

ReFresh

 

Link to comment

12 answers to this question

Recommended Posts

  • 0

What do you define in that DEBUG constants? O.o

I dont know what you mean with debug but for the rest you can check my changes out (I didnt test it):
 

<?PHP
if(isset($_SESSION['user_admin']) && checkInt($_SESSION['user_admin']) && $_SESSION['user_admin']>=0) {
    echo'<h2>'.DEBUG01.'</h2>';
    echo'<p>'.DEBUG02.'<br>'.DEBUG03.'<br/><br/><b>'.DEBUG04.'</b></p>';

    // when a charakter is selected and submitted
    $charId = isset($_POST['charakter']) ? $_POST['charakter'] : false;
    if ($charId && is_numeric($_POST['charakter'])) {
        $theId = htmlentities($_POST['charakter']);
        /*
         * ########################################
         * DEBUG HERE!!!
         * ########################################
         */
        echo 'Selected charakter with ID: '.$theId; // just to check that it works, you can delete this line
    }

    // show chars
    $sql = "SELECT player.id,player.name FROM ".SQL_HP_PLAYER.".player WHERE player.account_id='".$_SESSION['user_id']."'";
    $result = mysql_query($sql,$sqlServ);

    echo '<form method="post" action="'.basename($_SERVER["SCRIPT_FILENAME"]).'">';
    echo'<select name="charakter">';
    while($player = mysql_fetch_object($result)) {
        echo'<option value="'.$player->id.'">'.$player->name.'</option>';
    }
    echo '</select>';
    echo '<input type="submit" value="Debug selected Charakter"/>';
    echo '</form>';
}
else {
    echo'<table class="tabulka"><th><h3 class="tabulkaLostpwFont">Abys měl přístup do této sekce, musíš být přihlášen!</h3></th></table>';
}
?>
<?PHP
echo'<p><a href="/nastaveni">'.BACK.'</a></p>';
?>

 

Link to comment
  • 0

@Ayaka

That's something what I want but it's not complete because debug button don't work. In the file that I shared above you can find this adress: href="/debug_postavy/'.$ziskatPostavy->id.'" which was doing the debug of selected character. I need to debug selected character which was bugged somewhere in some map ingame. Can you fill this missing adress correctly? 

The adress must looks like that, but this don't work:

<input type="submit" value="Debug selected Charakter"><a href="/debug_postavy/'.$player->id.'">[Debug]</a>';

There's a script which debugging selected characters (I'm sorry I forgot to include this file into the my post above):

http://pastebin.com/SAQwh9PV

PS: In DEBUG constant is defined translation. For example banán (czech) means Banana (english)

Thanks

Link to comment
  • 0

OK at first we have to fix the functionality.

Use this code: http://pastebin.com/nWP5Vtgy
and replace on line 31:

<td class="'.$design.'">'.$ziskatPostavy->name.'<a href="/debug_postavy/'.$ziskatPostavy->id.'">[Debug]</a></td>

with:

<td class="'.$design.'">'.$ziskatPostavy->name.'<a href="/debug_postavy.php?postava='.$ziskatPostavy->id.'">[Debug]</a></td>

Does it work then? After that we do the select thing but it should work at first.

Link to comment
  • 0

@Ayaka

My scripts worked before but I only need to include the names of chars as option to select and then when I click on the buton the selected character will be debugged. So functionality of my scripts are 100% but missing the select tag with the names to debug.

You did it but the button which must debug the selected char didn't work.

IMG_20170209_172511_727.JPG

 

And there's no difference between this:

href="/debug_postavy/'.$ziskatPostavy->id.'">

and this:

href="/debug_postavy.php?postava='.$ziskatPostavy->id.'">

Because of I'm using rewriting by .htaccess.

Link to comment
  • 0

This worked?? I dont get where $_GET['postava'] came from if its not given in the url but ok. Check this out:


<?PHP

if(isset($_SESSION['user_admin']) && checkInt($_SESSION['user_admin']) && $_SESSION['user_admin']>=0) {

    echo'<h2>'.DEBUG01.'</h2>';

    echo'<p>'.DEBUG02.'<br>'.DEBUG03.'<br/><br/><b>'.DEBUG04.'</b></p>';

    $databazePostavy = "SELECT player.id,player.name FROM ".SQL_HP_PLAYER.".player WHERE player.account_id='".$_SESSION['user_id']."'";
    $queryPostavy = mysql_query($databazePostavy,$sqlServ);

    echo '<form method="post" action="/debug_postavy/">';
    echo'<select name="postava">';
    while($ziskatPostavy = mysql_fetch_object($queryPostavy)) {
        echo'<option value="'.$ziskatPostavy->id.'">'.$ziskatPostavy->name.'</option>';
    }
    echo '</select>';
    echo '<input type="submit" value="[Debug]"/>';
    echo '</form>';
}
else {
    echo'<table class="tabulka"><th><h3 class="tabulkaLostpwFont">Abys měl přístup do této sekce, musíš být přihlášen!</h3></th></table>';
}
?>
<?PHP
echo'<p><a href="/nastaveni">'.BACK.'</a></p>';
?>

If this doesn't work i cant help you because i dont get how this POST is working in your script

Link to comment
  • 0
27 minutes ago, ReFresh said:

@Ayaka It can't work because the action="/debug_postavy/ can't get the ID of the char so that's the problem.

yes, because in your other script you get the id with the GET Parameter "postava". Normaly a link should look like this:  /debug_postavy.php?postava='.$ziskatPostavy->id.'

postava (in my example) is declared in the select (name="postava") and the value is the ID. 

If you do .htaccess changes and normal links like above are working you can try it like i did with one change in action:

<?PHP

if(isset($_SESSION['user_admin']) && checkInt($_SESSION['user_admin']) && $_SESSION['user_admin']>=0) {

    echo'<h2>'.DEBUG01.'</h2>';

    echo'<p>'.DEBUG02.'<br>'.DEBUG03.'<br/><br/><b>'.DEBUG04.'</b></p>';

    $databazePostavy = "SELECT player.id,player.name FROM ".SQL_HP_PLAYER.".player WHERE player.account_id='".$_SESSION['user_id']."'";
    $queryPostavy = mysql_query($databazePostavy,$sqlServ);

    echo '<form method="post" action="/debug_postavy.php">';
    echo'<select name="postava">';
    while($ziskatPostavy = mysql_fetch_object($queryPostavy)) {
        echo'<option value="'.$ziskatPostavy->id.'">'.$ziskatPostavy->name.'</option>';
    }
    echo '</select>';
    echo '<input type="submit" value="[Debug]"/>';
    echo '</form>';
}
else {
    echo'<table class="tabulka"><th><h3 class="tabulkaLostpwFont">Abys měl přístup do této sekce, musíš být přihlášen!</h3></th></table>';
}
?>
<?PHP
echo'<p><a href="/nastaveni">'.BACK.'</a></p>';
?>

 

EDIT:// Ah and IMPORTANT: 

Change all (Line 7, 11, 24):

$_GET['postava']

to

$_POST['postava']

in this file: http://pastebin.com/SAQwh9PV

because its a post, not a get when submit via <form>!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Read our Rules
  • Activity

    1. 0

      PHOENIX2 !OLDSCHOOL SERVER, PAYTOWIN REMOVED!

    2. 2

      Fix CursorImage 'NoneType' object is not callable.

    3. 0

      [Land of Heroes] We are looking for Game / Game Economy Designers

    4. 177

      Render Target Remastered

    5. 1

      MySQL stop when start server

    6. 0

  • Recently Browsing

    No registered users viewing this page.

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.