所以我现在已经在这个问题上打了很长一段时间,而且就像在一个陌生的城市中迷路一样,我终于打破了方向!我正在使用数据库中的值开发表,但还需要一个将处理用户输入的列。我已经能够显示表,但我的输入没有更新必要的数据库元素。代码如下:
<?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语句中,一切都停止了......或者我应该说,虽然事情看起来很漂亮,但它们不起作用!在此先感谢,感谢任何帮助!
答案 0 :(得分:0)
确保您有$ tbl2_name检查的正确值
var_dump($tbl2_name)
更新前代码中的
并且对于调试尝试使用字符串连接,如
"UPDATE " . $tbl2_name . " SET paidsat = ? WHERE firstname=? and lastname=?";
并尝试使用
if( $paidsat != NULL )
并最后检查您是否有适当的更新值
paidsat = ? WHERE firstname=? and lastname=?
尝试
var_dump( $paidsat);
var_dump( $firstname);
var_dump( $lastname);
如果您将数学值与您想到的行进行数值计算,则构建一个正确的测试选项 在你的数据库控制台中测试这个选择