所以我一直在關閉這個問題已經有一段時間了,就像在一個陌生的城市裏開車四處奔波一樣,我終於打破了方向!我正在使用數據庫中的值開發表,但還需要一個處理用戶輸入的列。我已經能夠顯示錶格,但我的輸入沒有更新必要的數據庫元素。代碼如下:帶有數據庫值和用戶輸入的表格
<?php
include("pogsatbetbuddy.inc.php");
$cxn=mysqli_connect($host,$username,$password,$db_name)
or die("Did Not Connect");
$query="SELECT * FROM $tbl2_name ORDER BY $tbl2_name.$col_name ASC";
$result=mysqli_query($cxn,$query)
or die("Query Not Working");
echo"<table border='1'
<form name='payments' action='' method='POST'>
<tr>
<td class='update' colspan='5'>
<button data-theme='b' id='submit' type='submit'>Update</button>
</td>
</tr>
<tr>
<th class='profile'>Last Name</th>
<th class='profile'>First Name</th>
<th class='profile'>Saturday Payment Owing</th>
<th class='profile'>Enter Payment</th>
<th class='profile'>Saturday Balance</th>
</tr>";
while ($row=mysqli_fetch_assoc($result))
{
extract ($row);
echo"<tr>
<td class='profile'>$lastname</td>
<td class='profile'>$firstname</td>
<td class='profile'>$owingsat</td>
<td class='profile'><input type='number' name='paidsat' value=''/></td>
<td class='profile'>$owingsat-$paidsat</td>
</tr>";
}
echo "</form>";
echo "</table>";
這將以我想要的方式顯示錶格。通過以下代碼的結果,似乎我返回一個空值,所以我想我有一個表單操作或提交更新按鈕的問題,但經過多次實驗和搜索後找不到解決方案。下面的代碼餘額:
if(isset($_POST['paidsat']))
{
$paidsat = $_POST['paidsat'];
if(($paidsat) != null)
{
$stmt = $cxn->prepare("UPDATE $tbl2_name SET paidsat = ? WHERE firstname=? and lastname=?");
$stmt->bind_param('sss', $paidsat, $firstname, $lastname);
$status = $stmt->execute();
if($status === true) //To check if the execute was successful
{
echo("<p class='click'>You have successfully added the payment for $firstname $lastname\n<br /></p>");
}
}
else echo"Not Successful";
}
else echo "<p class='click'>Make your changes as required</p>";
mysqli_close($cxn);
一切即將崩潰停止在第二if語句.....或者我應該說,雖然事情看起來很漂亮,他們沒有發揮作用!在此先感謝,感謝任何幫助!
你在哪裏分配了$ tbl2_name? – scaisEdge
包含文件.... pogsatbetbuddy.inc.php – user3830570
我已經發布了第一個答案 – scaisEdge