【发布时间】:2011-09-09 02:16:49
【问题描述】:
通过我之前发布的这个链接Echo problem when a different user logs in,我设法解决或解决了我的问题。但不知何故,发生了一个小错误。虽然我的管理页面工作正常,但我的超级管理员和其他帐户开始输出错误(尽管它们并不是真正的错误)。员工ID和员工姓名在超级管理员页面和其他帐户中没有回显,但标题(文件上传)、文件日期和状态已回显。
//我的意思是,这就是回声假设的样子: *EmployeeID* *EmployeeName* *Title* *FileDate* *Status* 20132248 Danica 文件8 2001 年 1 月 8 日 已批准 20896647 Jan file7 2000 年 12 月 12 日 未批准 20864125 Keisha 文件2 2000 年 2 月 1 日 批准 16521253 Riorei 文件 2003 年 3 月 20 日 10 月 未批准 文件 3 2002 年 7 月 14 日 批准 //相反,它像这样回响 *EmployeeID* *EmployeeName* *Title* *FileDate* *Status* 文件8 2001 年 1 月 8 日 批准 file7 2000 年 12 月 12 日 未批准 20864125 Keisha 文件2 2000 年 2 月 1 日 批准 文件 2003 年 3 月 20 日 10 日 未批准 文件 3 2002 年 7 月 14 日 批准 //这是出现在我的本地主机上的实际输出这是我认为可能导致问题的一组代码,我将注释其中的 if 语句我认为问题导致错误
<?php
$search = '%';
$fgmembersite->DBLogin();
$limit = 5;
if(isset($_GET['offset'])) {
$offset = mysql_real_escape_string($_GET['offset']);
} else {
$offset = 0;
}
//for namelist a-z
$listname = '%';
If (isset($_GET['namelist']))
{
$listname = $_GET['namelist'];
}
//for search file
if(isset($_POST['searchfile']))
{
$search = $_POST['searchfile'];
}
else if(isset($_GET['searchfile']))
{
$search = $_GET['searchfile'];
}
if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa' OR $_SESSION[$fgmembersite->GetLoginSessionVar()] == 'admin')
{
//$sql="select * from gmdc_employee where employee_name like '%$search%' AND employee_name like '$listname%' ";
$sql="SELECT `e`.* FROM `gmdc_employee` `e` JOIN `gmdc_user` `u` ON ( `u`.`company_id` = `e`.`company_id` ) WHERE (`u`.`company_name` LIKE '%$search%' OR `e`.`employee_name` LIKE '%$search%' OR `e`.`employee_id` LIKE '%$search%') AND `e`.`employee_name` LIKE '$listname%' ";
}
else
{
$sql = "select `e`.* from `gmdc_user` `u`, `gmdc_employee` `e` where `u`.`username` = '".$_SESSION[$fgmembersite->GetLoginSessionVar()]."' and `u`.`company_id` = `e`.`company_id` AND `e`.`employee_name` like '$listname%' AND `e`.`employee_name` like '%$search%'";
}
$query = mysql_query("$sql ORDER BY `e`.`employee_name`, `e`.`confirmation` DESC ,`e`.`file_id` DESC,`e`.`file_date` DESC LIMIT $offset,$limit") or die ( mysql_error () );
$result = mysql_query($sql) or die (mysql_error());
$total = mysql_num_rows($result);
$emp_id = ""; //This will be use to remove employee_id if its already echoed.
$emp_name = ""; //This will be use to remove employee_name if its already echoed.
if(!$result || mysql_num_rows($result) <= 0)
{
$fgmembersite->HandleError("No file found.");
return false;
}
while ($row = mysql_fetch_assoc($query))
{
$file_id = $row['file_id'];
$file_desc = $row['file_description'];
$file_date = $row['file_date'];
$file_name = $row['file_name'];
$file_accs = $row['folder_access'];
$file_employee = $row['employee_id'];
$file_confir = $row['confirmation'];
$file_ename = ucwords($row['employee_name']);
$emp_id=$emp_id==$row['employee_id']?"":$row['employee_id'];
$emp_name=$emp_name==$row['employee_name']?"":$row['employee_name'];
$info = pathinfo($file_name);
$file_ext = $info['extension'];
if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
{
echo '<tr>
<td>
</td>
</tr>
<tr class="subone">
<td class="sub" width="100">
'.$emp_id.'
<br />
</td>';
if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
{
?><td class="sub" width="100">
<a href="" onclick = javascript:newPopup('addfile.php?emp=<?php echo $file_employee ?>');><?php echo$emp_name?></a>
<br />
</td><?php
}
else
{
echo '<td class="sub" width="182">
'.$emp_name.'
<br />
</td>';
}
echo'<td class="sub" width="218">
<a href="'.$file_accs.$file_name.'" target="_blank" style="text-decoration: underline;">'.$file_desc.'</a>
<br />
</td>
<td class="sub" width="100">
'.date('M d, Y',mktime(0,0,0,substr($file_date,5,2),substr($file_date,8,2),substr($file_date,0,4))).'
<br />
</td>
<td class="sub" width="100">
'.$file_confir.'
<br />
</td>';
if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
{
if($file_confir == 'Pending' OR $file_confir == 'NotApproved')
{
if(isset($_GET['id']))
{
$fgmembersite->Delete_Db($_GET['id']);
}
echo '<td class="sub" width="100">
<a href="index.php?id='.$file_id.'">Delete</a>
<br />
</td>';
}
}
/
}
//I THINK THE PROBLEM STARTS HERE
else if($_SESSION[$fgmembersite->GetLoginSessionVar()] != 'sa' && ($file_confir == 'Approved' || $file_confir == 'NotApproved'))
{
echo '<tr>
<td>
</td>
</tr>
<tr class="subone">
<td class="sub" width="100">
'.$emp_id.'
<br />
</td>';
if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
{
?><td class="sub" width="100">
<a href="" onclick = javascript:newPopup('addfile.php?emp=<?php echo $file_employee ?>');><?php echo$emp_name?></a>
<br />
</td><?php
}
else
{
echo '<td class="sub" width="182">
'.$emp_name.'
<br />
</td>';
}
echo'<td class="sub" width="218">
<a href="'.$file_accs.$file_name.'" target="_blank" style="text-decoration: underline;">'.$file_desc.'</a>
<br />
</td>
<td class="sub" width="100">
'.date('M d, Y',mktime(0,0,0,substr($file_date,5,2),substr($file_date,8,2),substr($file_date,0,4))).'
<br />
</td>
<td class="sub" width="100">
'.$file_confir.'
<br />
</td>';
if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
{
if($file_confir == 'Pending' OR $file_confir == 'NotApproved')
{
if(isset($_GET['id']))
{
$fgmembersite->Delete_Db($_GET['id']);
}
echo '<td class="sub" width="100">
<a href="index.php?id='.$file_id.'">Delete</a>
<br />
</td>';
}
}
}
}?>
我希望有人可以帮助我找出导致此输出的原因。 :( 已经花了一个多小时才弄清楚。感谢那些会回复的人。
MisaChan
【问题讨论】:
-
清理这些 lins 可能会有所帮助
$emp_id=$emp_id==$row['employee_id']?"":$row['employee_id'];和$emp_name=$emp_name==$row['employee_name']?"":$row['employee_name']; -
你确认你的 SQL 是正确的吗? SQL 对我来说似乎有点可疑。附带说明一下,在将用户输入应用到 SQL 以防止 SQL 注入之前,您应该始终对用户输入的任何内容进行转义。
-
@Lawrence Cherone :错误是输出本身。如我上面的示例所示。和@shinkou:是的,我已经这样做了。这就是为什么它的输出几乎是正确的。我认为问题出在这组代码
$emp_id=$emp_id==$row['employee_id']?"":$row['employee_id']; $emp_name=$emp_name==$row['employee_name']?"":$row['employee_name'];上,这是我使用的在其他帐户上完美运行的条件。 -
像
$emp_name=($emp_name==$row['employee_name'])?"":$row['employee_name'];那样做 -
@Lawrence Cherone,我照你说的做了,但没有任何改变。