【发布时间】:2014-12-21 03:51:34
【问题描述】:
按下“更新”按钮后,它应该更新然后显示更新记录记录的结果(带有选定列的单个更新记录)。但是,该页面仅显示表列名称,没有任何记录和一些错误。请帮忙。
<html>
<head>
<strong><font size="6">Sales Log - Main</font><font size="5"><br />
(Transaction Status Update)</font></strong>
</head>
<body bgcolor="#6E6E6E" text="Azure">
<?php
if(isset($_POST['update']))
{
$dbhost = 'localhost';
$dbuser = 'jack';
$dbpass = 'somepassword';
$myDBname = 'sales';
$conn = mysql_connect($dbhost, $dbuser, $dbpass, $myDBname);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$FileNumber = mysql_real_escape_string($_POST['FileNumber']);
$Status = mysql_real_escape_string($_POST['Status']);
//$sql = "UPDATE saleslog SET Status = '".$Status."' WHERE FileNumber = '".$FileNumber."'"; //this worked fine then code below was introduced
$sql = "UPDATE saleslog
SET Status = '$Status'
WHERE FileNumber = '$FileNumber'" ;
mysql_select_db('realestate');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully!\n";
mysql_close($conn);
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<br />
<br />
<td width="100">File Number</td>
<td><input name="FileNumber" type="text" id="FileNumber"></td>
</tr>
<tr>
<td width="100">Status</td>
<td><input name="Status" type="text" id="Status" value="Closed"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="update" type="submit" id="update" value="Update">
<input name="reset" type="reset" onclick="resetForm(''); return false;" />
</td>
</tr>
</table>
</form>
<?php
}
?>
$sql="SELECT FileNumber, Address, Status FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>
<tr>
<td align="center"><strong>FileNumber</strong></td>
<td align="center"><strong>Address</strong></td>
<td align="center"><strong>Status</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['FileNumber']; ?></td>
<td><? echo $rows['Address']; ?></td>
<td><? echo $rows['Status']; ?></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>
【问题讨论】:
-
更新了答案。这是一个工作程序。删除标记为 '/* 删除行 */ 的行
-
添加了“找到的行”摘要行。您不需要删除任何行,它应该可以工作。我将添加表格外观的详细信息,以确保我们具有相同的表格布局。请记住,所有名称必须完全匹配字母大小写。它在这里工作正常。它显示更新后的更新行。它应该适用于 5.3 之前的 PHP 版本。
-
终于找到了原因“...但是它仍然没有显示最后编辑的记录或任何记录。”。尝试回显记录中的数据时,我使用了错误的 PHP 标记。现在已经修好了。请参阅代码中的“=”或单击答案底部的“已编辑
”链接以查看更改。 “迟到总比没有好……”叹息。 ;-/