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;
}