1

I'm not sure about the title, I tried my best. I have a table displayed with information from a database using this file

display.php

<?php

    mysql_connect("localhost", "root", "root") or die(mysql_error());
    mysql_select_db("tournaments") or die(mysql_error());

    $result = mysql_query("SELECT * FROM tournies") 
    or die(mysql_error());  

    echo '<table id="bets" class="tablesorter" cellspacing="0" summary="Datapass">
<thead>
    <tr>
        <th>Tournament <br> Name</th> 
        <th>Pot</th> 
        <th>Maximum <br> Players</th> 
        <th>Minimum <br> Players</th> 
        <th>Host</th> 
        <th></th>
        <th></th>
    </tr>
</thead>
<tbody>';



    while($row = mysql_fetch_array( $result )) {

       $i=0; if( $i % 2 == 0 ) {
            $class = "";
        } else {
            $class = "";
        }

        echo "<tr" . $class . "><td>"; 
        echo $row['tour_name'];
        $tour_id = $row['tour_name'];
        echo "</td><td>"; 
        echo $row['pot']," Tokens";
        echo "</td><td class=\"BR\">"; 
        echo $row['max_players']," Players";
        echo "</td><td class=\"BR\">"; 
        echo $row['min_players']," Players";
        echo "</td><td class=\"BR\">";
        echo $row['host'];
        echo "</td><td>";
        echo "<input id=\"delete_button\" type=\"button\" value=\"Delete Row\" onClick=\"SomeDeleteRowFunction(this)\">";
        echo "</td><td>";
        echo "<form action=\"join.php?name=$name\" method=\"POST\" >";
        echo "<input id=\"join_button\" type=\"submit\" value=\"Join\">";
        echo "</td></tr>"; 
    } 

    echo "</tbody></table>";
?>

Basically I want the user to press a button from a row of the table and they go to a new page called join.php. I need the persons username and the name of the tournament from the row the clicked.

For example here's my page: my page

When they click the join button at the end of row one it should send them to

'join.php?name=thierusernamehere&tourname=dfgdds'

Any help much appreciated. Thanks.

3
  • 1
    where's the username data? Commented Sep 4, 2013 at 0:52
  • Just add a hidden field (echo "<input name=\"name\" type=\"hidden\" value=\"".$name."\">"; for example) to the form with the username & tourname. Commented Sep 4, 2013 at 0:53
  • 2
    PSA: The mysql_* functions are deprecated in PHP 5.5. It is not recommended for writing new code as it will prevent you from upgrading in the future. Instead, use either MySQLi or PDO and be a better PHP Developer. Commented Sep 4, 2013 at 0:55

2 Answers 2

2
echo '<td><a href="join.php?name='.$row['name'].'&tourname='.$row['tour_name'].'">Join</a></td>'
Sign up to request clarification or add additional context in comments.

2 Comments

name doesn't appear to be part of the resultset.
@AndreeCrist Just had to fix a few naming errors and it worked like a charm, thanks.
0

There are many way to approach.

The easiest way is just echo '<a href="join.php?name=' . $row['col_name'] . '">JOIN</a>';

or you can use a form with hidden input and submit button.

BUT

Your code is really a mess, try to make your code more maintainable and readable. And do NOT use any mysql_* functions, they are deprecated.

Read more about PDO:

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.