我正在尝试在HTML表单中创建一个按钮,在相应的mySQL位置添加一个数字。基本上,一个帖子的投票选项。现在,按钮都做同样的事情:他们从底部提交原始帖子查询。我如何让他们单独行动?
PHP:
if (!$thepipeline) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
if (!empty ($_POST)) {
$squery = "INSERT INTO votes (votes) VALUE (1)";
print $squery;
$votes_result = mysqli_query ($thepipeline, $squery);
}
$query = "SELECT p.post_id, p.member_id, p.content, p.date_created,
SUM(v.votes) AS votes_total
FROM posts p LEFT JOIN
votes v
ON p.post_id = v.post_id
GROUP BY post_id
ORDER BY votes_total;";
echo "<table>\n";
echo '<tr>
<td> USER ID</td>
<td> PROPOSAL</td>
<td> DATE POSTED</td>
<td> SCORE</td>
</tr>';
if ($amorphous_cloud = mysqli_query ($thepipeline,$query)) {
while ($row = mysqli_fetch_assoc ($amorphous_cloud)){
echo '<tr>
<td> ' . $row['member_id'].'</td>
<td> ' . $row['content'].'</td>
<td> ' . $row['date_created'].'</td>
<td> ' . $row['votes_total'].'
<br><form method="POST"><input type="button" name="vote" value="Vote" /></form></td>
</tr>';
}
}
else {
print ":(";
}
echo "</table>\n";
?>
<br>
</div>
<div id="addpost">
<h3>Enter Proposal</h3>
<p>Off-topic posts will be deleted without warning.</p>
<?php
$member_id = $_GET['member_id'];
$content = $_GET['content'];
$link = mysqli_connect ('localhost', '******', '************,', '*************');
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
if (!empty ($_GET)) {
$query = "INSERT INTO posts (member_id, content) VALUES ('".$member_id."', '".$content."')";
print $query;
$member_result = mysqli_query ($link, $query);
}
$user_query = "SELECT member_id, member_name FROM members";
$user_result = mysqli_query ($link, $user_query);
$user_html = "";
while ($row = mysqli_fetch_assoc ($user_result)) {
$user_html = $user_html . "<option value='".$row['member_id']."'>".$row['member_name']."</option>\n";
}
?>
<form method="GET">
<!-- member -->
<p>Member</br>
<select name="member_id" >
<?php echo $user_html; ?>
</select>
</p>
<!-- date -->
<p>Content
</p>
<textarea name="content" cols="40" rows="5"></textarea>
</br>
<input type="submit" />
</form>
</div>
</div>