我的php脚本有问题,所以基本上我将数据库值放入$ result,然后将$ row并在其中使用$ row ['blabla'],依此类推。问题是我似乎无法发送该特定ID或该数据库行,而不仅仅是将一行增加X,所有行列的值也增加X
这是第一个功能。
function listEvents($conn) {
$sql = "SELECT * FROM basicevents";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
if($row['EventCurrFunds'] < $row['EventMaxFunds']) {
echo "<div class='container border border-info'>
<div class='row pb-3 text-center'>
<div class='col-md p-3 border border-info'>" . $row['EventName'] . "</div>
<div class='vol-md p-3 border border-info'>" . $row['EventDate'] . "</div>
</div>
<div class='row pb-3 text-center'>
<div class='col-md p-3 border border-info'>
Capacity = " . $row['EventCapacity'] . "
</div>
<div class='col-md p-3 border border-info'>
" . $row['EventCurrFunds'] . "/" . $row['EventMaxFunds'] . "
</div>
</div>
<div class='col-md p-3 border border-info'>
<form class='border border-info' action='" . addFunds($conn, $row['EventID']) . "' method='POST'>
<div class='form-group'>
<label for='funds'>Enter funds</label>
<input type='number' class='form-control w-50' placeholder='Enter required funding' name='funds'>
</div>
<button type='submit' name='fundsSubmit' class='btn btn-info p-2 w-25'>Add funds</button>
</form>
</div>
</div><br>";
}
}
}
}
通过$ _POST输入后,通过调用addFunds()来增加EventCurrFunds
function addFunds($conn, $id) {
if(isset($_POST['fundsSubmit'])) {
$aux = $_POST['funds'];
$sql = "UPDATE basicevents SET EventCurrFunds = EventCurrFunds + '$aux' WHERE EventID = '$id'";
$result = mysqli_query($conn, $sql);
}
}
我尝试在发信号时提供该ID的具体信息,但是id无效。基本事件EventCurrFunds的所有列值都增加了,而不仅仅是我要赋予addFunds函数ID的列值。
答案 0 :(得分:0)
此行<form class='border border-info' action='" . addFunds($conn, $row['EventID']) . "' method='POST'>
是错误的
您可以使用:
<form class='border border-info' action='./?id=" . $row['EventID'] . "' method='POST'>
因此您可以从$_GET['id']
添加
如果您希望所有人都进入$_POST
,则可以执行以下操作:
<form class='border border-info' action='' method='POST'>
<input type='hidden' name='eventid' value='". $row['EventID'] .">
因此您可以从$_POST['eventid']