我一直盯着这个页面待了一个多小时。我的更新功能似乎没有更新。当我通过SQL尝试它似乎没问题。我在此页面底部有一个表单,用于更新表格中的字段。谁能发现错误?
<?php
// First of all initialise the user and check for permissions
require_once "/var/www/users/user.php";
$user = new CHUser(2);
// Initialise the template
require_once "/var/www/template/template.php";
$template = new CHTemplate();
// And create a cid object
require_once "/var/www/Testing/DisplayWIPOnLocation.php";
$BundleProgress= new CHWIPProgress();
if(isset($_GET['Reference'])){
$todays_date = date("Y-m-d H:i:s");
$content .= " <h3> Details for Bundle : $reference </h3> ";
$bundle = $BundleProgress->GetBundle($_GET['Reference']);
$reference = $_GET['Reference'];
// Now show the details
foreach($bundle as $x){
$content .= "
<table>
<tr>
<th> Location </th>
<td>" . $x['Description'] . "</td>
</tr>
<tr>
<th> Works Order Number </th>
<td>" . $x['WorksOrder'] . "</td>
</tr>
<tr>
<th> Bundle Number </th>
<td>" . $x['Number'] . "</td>
</tr>
<tr>
<th>Qty Issued</th>
<td>" . $x['Qty'] . "</td>
</tr>
<tr>
<th>Bundle Reference </th>
<td>" . $x['Reference'] . "</td>
</tr>
<tr>
<th>Style description</th>
<td>" . $x['Stock'] . "</td>
</tr>
<tr>
<th>Due Date</th>
<td>" . $x['DueDate'] . "</td>
</tr>
<tr>
<th>Date In </th>
<td>" . $x['DateIN'] . "</td>
</tr>
<tr>
<th>Date Out</th>
<td>" . $x['DateOUT'] . "</td>
</tr>
<tr>
<th>Last Code</th>
<td>" . $x['Last'] . "</td>
</tr>
</table>
<br> ";
}
$content .= " </table>
<form action='viewBundle.php?step=2' method='post'>
<p>Reason: <input type='text' name='reason' /><br
/><p>
<p><input type='hidden' name='bundlereference'
id='Username' value='" . $x['Reference'] . "' />
<input type='submit' name ='add'/></form>
</table> ";
if($_GET['step'] == 2) {
$BundleProgress->UpdateReason($_POST['reason'],$_POST['bundlereference']);
$content .= " <a href='index.php?location=" .
$x['Description'] . "'> updated</a> ";
}
}
else {
$content .= "<h3>Something has gone wrong</h3>
<br>
<a href='index.php?location=" . $x['Description'] . "'> Return to Previous
Page </a>
";
}
$template->SetTag("content", $content);
echo $template->Display();
?>
功能
public function UpdateReason($reason, $bundlereference) {
$sql = "UPDATE `ArchiveBundle`
SET `Issue` = " . $reason . "
WHERE `BundleReference` = " . $bundlereference .
";";
mysql_select_db(DB_DATABASE_NAME, $this->conn);
return mysql_query($sql, $this->conn);
}
答案 0 :(得分:4)
变化:
if($_GET['step'] == 2)
为:
if((int)$_GET['step'] === 2)
和
public function UpdateReason($reason, $bundlereference) {
$sql = "UPDATE `ArchiveBundle`
SET `Issue` = " . $reason . "
WHERE `BundleReference` = " . $bundlereference .
";";
mysql_select_db(DB_DATABASE_NAME, $this->conn);
return mysql_query($sql, $this->conn);
}
为:
public function UpdateReason($reason, $bundlereference) {
mysql_select_db(DB_DATABASE_NAME, $this->conn);
$_reason = mysql_real_escape_string($reason,$this->conn);
$_bundlereference = mysql_real_escape_string($bundlereference,$this->conn);
$sql = "UPDATE `ArchiveBundle`
SET `Issue` = '" . $_reason . "'
WHERE `BundleReference` = '" . $_bundlereference . "'";
return mysql_query($sql, $this->conn);
}
试试吧。代码尚未经过测试,但它是一个很好的起点。
要尝试调试此处发生的事情,请执行以下操作:
public function UpdateReason($reason, $bundlereference) {
error_reporting(E_ALL ^ E_NOTICE);
$db_selected = mysql_select_db(DB_DATABASE_NAME, $this->conn);
if (!$db_selected) {
die("Can't use db : " . mysql_error());
}
$_reason = mysql_real_escape_string($reason,$this->conn);
$_bundlereference = mysql_real_escape_string($bundlereference,$this->conn);
$sql = "UPDATE `ArchiveBundle`
SET `Issue` = '" . $_reason . "'
WHERE `BundleReference` = '" . $_bundlereference . "'";
mysql_query($sql, $this->conn);
die(mysql_error());
}
此外,在您提交表单时,您似乎没有传入Reference参数,因此当您发布表单时,if(isset($ _ GET ['Reference']))将失败。我已经更改了下面的表格和表单代码以使其更具可读性,在表单提交时传递Reference参数,并在获取数据集之前更新db记录,以便您在返回的表中看到更新的记录。 / p>
// First of all initialise the user and check for permissions
require_once "/var/www/users/user.php";
$user = new CHUser(2);
// Initialise the template
require_once "/var/www/template/template.php";
$template = new CHTemplate();
// And create a cid object
require_once "/var/www/Testing/DisplayWIPOnLocation.php";
$BundleProgress= new CHWIPProgress();
if(isset($_GET['Reference'])){
if($_GET['step'] == 2) {
$BundleProgress->UpdateReason($_POST['reason'],$_POST['bundlereference']);
}
$todays_date = date("Y-m-d H:i:s");
$content .= " <h3> Details for Bundle : $reference </h3> ";
$bundle = $BundleProgress->GetBundle($_GET['Reference']);
$reference = $_GET['Reference'];
// Now show the details
foreach($bundle as $x){
$content .= "
<table>
<tr><th> Location </th><td>" . $x['Description'] . "</td></tr>
<tr><th> Works Order Number </th><td>" . $x['WorksOrder'] . "</td></tr>
<tr><th> Bundle Number </th><td>" . $x['Number'] . "</td></tr>
<tr><th>Qty Issued</th><td>" . $x['Qty'] . "</td></tr>
<tr><th>Bundle Reference </th><td>" . $x['Reference'] . "</td></tr>
<tr><th>Style description</th><td>" . $x['Stock'] . "</td></tr>
<tr><th>Due Date</th><td>" . $x['DueDate'] . "</td></tr>
<tr><th>Date In </th><td>" . $x['DateIN'] . "</td></tr>
<tr><th>Date Out</th><td>" . $x['DateOUT'] . "</td></tr>
<tr><th>Last Code</th><td>" . $x['Last'] . "</td></tr>
</table>
<br>";
}
$content .= "<table>
<form action='viewBundle.php?Reference=" . $_GET['Reference'] . "&step=2' method='post'>
<p>Reason: <input type='text' name='reason' /></p><br/>
<p><input type='hidden' name='bundlereference' id='Username' value='" . $x['Reference'] . "' /></p>
<input type='submit' name ='add'/>
</form>
</table>";
} else {
$content .= "<h3>Something has gone wrong</h3>
<br>
<a href='index.php?location=" . $x['Description'] . "'> Return to Previous Page </a>
";
}
$template->SetTag("content", $content);
echo $template->Display();
答案 1 :(得分:0)
我可以建议您首先检查mysql_query返回的内容。也许这个特定的变量定义不正确。另请记住在查询中添加引号。