此页面生成一个包含所有内容的表格 我数据库中billing_reports表的数据。当你加倍 单击某个项目,您可以在该字段中输入新值,然后按 输入保存。问题是,当我按提交时,它 只刷新页面,而不更新对数据库的更改。 我该如何解决?
<?php
include_once ("includes/config.php");
include_once ("includes/functions.php");
include_once ("includes/header.php");
?>
<!--How this works, is that this page generates a table that containes all
the data on the billing_reports table in my database. When you double
click on an item, you can enter in a new value in the field, then press
enter to save. The problem I am having, is that when I press submit it
just refreshes the page, when I want it to update the changes to the database.
How do I fix this? -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<?php
// $data = All the rows in billing reports
$data = mysql_query("SELECT * FROM billing_reports")
or die(mysql_error());
// This is printing the Javascript table listed above
?> <table class="editableTable"> <?php
Print "<editableTable border cellpadding=4>";
//This is defining $info as the action that seperates the $data pulled from the database
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$info['cc_name'] . "</td> ";
Print "<th>ID:</th> <td>".$info['br_id'] . "</td> ";
Print "<th>Listing ID:</th> <td>".$info['listing_id'] . "</td> ";
Print "<th>Payment:</th> <td>".$info['billing_amount'] . "</td> ";
Print "<th>Status:</th> <td>".$info['status'] . " </td></tr>";
}
Print "</table>";
if (!$_POST['submit']) {
$result = mysql_query($info);
$person = mysql_fetch_array($result);
}
if(isset($_POST['submit'])) {
$info = "UPDATE billing_reports SET cc_name='$_POST[cc_name]', br_id='$_POST[br_id]', listing_id='$_POST[listing_id]', billing_amount='$_POST[billing_amount]', status='$_POST[status]'";
mysql_query($info) or die(mysql_error());
echo"Agent has been modified!";
}
?>
<form action="" method="post" class="button">
<li>Save Changes</br>
<input type="submit" <name="submit" value="Modify"/></li>
</form>
<?php
include_once ("includes/footer.php");
?>
答案 0 :(得分:3)
您的输入中存在误导,导致输入本身不起作用,isset()
提交永远不会是真的
<input type="submit" <name="submit" value="Modify"/></li>
//^ here you don't need <
另一方面,我不会建议您极易受mysql injections
攻击,我宁愿切换到pdo或mysqli并使用预备语句
答案 1 :(得分:1)
此行中有一个拼写错误,<
之前name
:
<input type="submit" <name="submit" value="Modify"/></li>
通常建议使用带代码突出显示的编辑器。