随机数组并插入数据库; 在当前之前插入元素

Every time I click submit the name of the element from the array I'm voting on changes when saved into database. The element that shows up after the current echoed element is entered into the database instead of the one I clicked on. Any suggestions on how make the element from the array I click on save into the database? I can't seem to figure it out.

I've tried using lists and unshift still get the same result.

Lets say the echo shows example2 on for the value in the form. I click example2 but example1 gets saved in the database. I'm not sure how to fix this. Thanks for the help.

Here's my code:

The array setup I'm using:

$array = array("example1","example2","example3");
shuffle($array);
foreach($array as $random);

<?php echo array_pop($random);?>

HTML:

   <tbody>
         <tr>
                <form action="Voting_action.php" method="post">
            <td>
                <input type="submit" class="buttontable1" value="<?php echo $random ?>" name="name"/>
            </td>
                </form>
          </tr>
    </tbody>

PHP: Action

$mysqli = new mysqli("", "", "", "");
if ($mysqli->connect_error) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_error . ") " . $mysqli->connect_error;
}
if (!$mysqli->query("INSERT INTO table(id, name, votes) VALUES (id, '".$random."', '".$votes."')")) {
    echo "Multi-INSERT failed: (" . $mysqli->errno . ") " . $mysqli->error;
}

your html form sends your random key using name="name" (which is confusing in itself).

Access that variable via $_POST['name'] not $random.

Given problems like this in the future, in the first instance always do

var_dump($_POST);

in your form handler in order to see what variables are available to be used, and what values they carry.

Ps the way you have used unfiltered and unescaped values in you db query leaves you wide open to sql injection attacks, look into Mysqli's prepared statements to sidestep this issue.