Jump to content

PHP - insert $ into a Select/Option HTML tag


Recommended Posts

  • Active Member

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:

I will be glad if someone can help me.

There's example how it will looks:

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

Thanks for answers!

Sincerely,

ReFresh

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

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
Share on other sites

  • Active Member

@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: .'" 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:

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

Thanks

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

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
Share on other sites

  • Active Member

@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.

And there's no difference between this:

Because of I'm using rewriting by .htaccess.

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

  • Active Member

@Ayaka 

PS: I will edit the post so wait 30 seconds. Still don't work :D But before the scripts working look:

After clicking on debug I was redirect to http://example.com(159 is ID of debuged character)

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

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.