execor execor - 5 months ago 20
MySQL Question

Fetching data from MySQL to dropdown and POSTing doesn't work

I have site with signups for tournament with ladder system. Everything works except one thing. I made simple subpage to assign teams manually (need that), it is table inside form with dropdowns.

http://prnt.sc/cdpam5 < picture of how it looks like

Problem is - when I pick team from dropdown list and then click Submit button, all I get are variables eg. team1, team2 when it's supposed to be "Wojtuś Pro", "kinaszonators" in this case.


include 'db.php';

$con = mysqli_connect($host, $user, $pass, $db);
if (!$con) {
die('Database connection error: ' . mysqli_connect_error());

$sql = "SELECT team FROM lan_signups WHERE id='".$i."'";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result) > 0){
$row = mysqli_fetch_assoc($result);
${'team'.$i} = $row['team'];
$row = mysqli_fetch_assoc($result);
${'team'.$i} = "brak drużyny"; // means blank


Is something wrong with that form? I didn't post here the whole table code, it's little bit messy and not important:

index.php still

<form name="ladder" method="post" action="done.php">
<div class="tg-wrap">
<table class="tg">
<td class="tg-031e">1A
<select style="width: auto;" name="a1">
<option value="blank">-</option>
<option value="team1"><?php echo $team1 ?></option>
<option value="team2"><?php echo $team2 ?></option>
<option value="team15"><?php echo $team15 ?></option>
<option value="team16"><?php echo $team16 ?></option>
<input type="submit" style="float:right;" value="save">



$a1 = $_POST['a1'];
echo $a1;

This should return "Wojtuś Pro" from database but returns team1. I've tried GET and the same. I just don't know what's the reason my variable is not "transfered" to data and only variable's name is submitted.

Sorry if it is messy, but I am not so experienced in coding. To be clear, I want to get content from database, fill up dropdown with that, and post my choice further via form to another php and then save it to database(that i can do myself). I will be very, very grateful!


Your code returns team1, team2 or so on because you set values for options in the select like team1, team and so on. You code for option definition should look like:

<option value="<?php echo $team1 ?>"><?php echo $team1 ?></option>