【发布时间】:2015-08-18 13:50:57
【问题描述】:
我一直在制作一个待办事项列表,该列表使具有管理员权限的人能够从表单中编辑/更新公司内所有员工的多个百分比。发送的数据可以是 50-200 个条目之间的任何地方,并且会一次更新。
我一直面临的问题是表单和页面在我的 XAMPP 本地计算机上运行良好,并且运行更新的动作,但是,一旦我将其上传到实时 FTP,它就不会。在实时服务器上,当我单击提交按钮时,它会加载并刷新页面,但没有更新任何值,也不会重定向到正确的页面(实际上它停留在同一页面上)。
我的 PHP 有点生疏,解决方案可能很简单,但对于我的生活,我似乎无法解决它。
这是我的代码,任何在这方面的建设性批评都将受到高度赞赏。
<strong>Update Bulk To Do List</strong><br><br>
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="kpi"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY country, person, type, lpad(jobnr, 100, 0)";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class='responsive'>
<form name="form1" method="post" action="">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<col width=3%>
<col width=5%>
<col width=3%>
<col width=15%>
<col width=35%>
<col width=15%>
<col width=18%>
<tr style='color: #fff; border-top: #d2d8db solid 2px; border-bottom: #d2d8db solid 2px'>
<td id='blue' bgcolor='#39a8f9' align="left" ><strong>ID</strong></td>
<td id='blue' bgcolor='#39a8f9' align="center"><strong>Name</strong></td>
<td id='blue' bgcolor='#39a8f9' align="center"><strong>No.</strong></td>
<td id='blue' bgcolor='#39a8f9' align="center"><strong>Brief</strong></td>
<td id='blue' bgcolor='#39a8f9' align="center"><strong>Detail</strong></td>
<td id='blue' bgcolor='#39a8f9' align="center"><strong>Type</strong></td>
<td id='blue' bgcolor='#39a8f9' align="center"><strong>%</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="left" id='hovereff' style='border-bottom: #d2d8db solid 1px!important;'><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td>
<td align="center" bgcolor='#2c3e6c' id='hovereff' style='border-bottom: #d2d8db solid 1px!important;'><?php echo $rows['person']; ?><input type='hidden' id='person' name='person[]' value="<?php echo $rows['person']; ?>"></td>
<td align="center" bgcolor='#2c3e6c' id='hovereff' style='border-bottom: #d2d8db solid 1px!important;'><?php echo $rows['jobnr']; ?><input type='hidden' id='jobnr' name='jobnr[]' value="<?php echo $rows['jobnr']; ?>"></td>
<td align="left" bgcolor='#2c3e6c' id='hovereff' style='border-bottom: #d2d8db solid 1px!important;'><?php echo $rows['brief']; ?><input type='hidden' id='brief' name='brief[]' value="<?php echo $rows['brief']; ?>"></td>
<td align="left" bgcolor='#2c3e6c' id='hovereff' style='border-bottom: #d2d8db solid 1px!important;'><?php echo $rows['detail']; ?><input type='hidden' id='detail' name='detail[]' value="<?php echo $rows['detail']; ?>"></td>
<td align="center" bgcolor='#2c3e6c' id='hovereff' style='border-bottom: #d2d8db solid 1px!important;'><?php echo $rows['type']; ?><input type='hidden' id='type' name='type[]' value="<?php echo $rows['type']; ?>"></td>
<td align="center" bgcolor='#2c3e6c' id='hovereff' style='border-bottom: #d2d8db solid 1px!important;'>
<input name="overall_result[]" type="text" id="overall_result" value="<?php echo $rows['overall_result']; ?>">
<input type='hidden' id='expectation' name='expectation[]' value="<?php echo $rows['expectation']; ?>">
<input type='hidden' id='comments' name='comments[]' value="<?php echo $rows['comments']; ?>">
<input type='hidden' id='status' name='status[]' value="<?php echo $rows['status']; ?>">
<input type='hidden' id='country' name='country[]' value="<?php echo $rows['country']; ?>">
<input type='hidden' id='week' name='week[]' value="<?php date('d/m/Y', strtotime("Next Friday"))?>">
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="7" align="right"><input type="submit" name="submit" class="upbutton" value="Update List"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "submit" is active, do this
if(isset($_POST['submit'])){
$person=$_POST['person'];
$jobnr=$_POST['jobnr'];
$brief=$_POST['brief'];
$detail=$_POST['detail'];
$overall_result=$_POST['overall_result'];
$comments=$_POST['comments'];
$status=$_POST['status'];
$country=$_POST['country'];
$week=$_POST['week'];
$expectation=$_POST['expectation'];
$type=$_POST['type'];
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET person='$person[$i]', jobnr='$jobnr[$i]', brief='$brief[$i]' , detail='$detail[$i]' , expectation='$expectation[$i]', overall_result='$overall_result[$i]' , comments='$comments[$i]', status='$status[$i]', country='$country[$i]' , type='$type[$i]' , week='$week[$i]' WHERE id='$id[$i]'";
$query4=mysql_query("UPDATE kpi_ytd SET person='$person[$i]', jobnr='$jobnr[$i]', brief='$brief[$i]' , detail='$detail[$i]' , expectation='$expectation[$i]', overall_result='$overall_result[$i]' , comments='$comments[$i]', status='$status[$i]', country='$country[$i]' , type='$type[$i]' , week='$week[$i]' WHERE id='$id[$i]'");
$query5=mysql_query("insert into kpi_records values('','$person[$i]','$jobnr[$i]','$week[$i]','$brief[$i]','$detail[$i]','$expectation[$i]','$overall_result[$i]','$comments[$i]', '$status[$i]', '$country[$i]', '$type[$i]')");
$result1=mysql_query($sql1);
}
}
if(isset($result1)){
echo("<h3>Please Wait,<br>Updating Branch Tasks...</h3><script>location.href = '/list.php';</script>");
}
?>
【问题讨论】:
-
您很容易受到sql injection attacks 的攻击,只是假设您的查询应该有效。不好的假设。永远不要假设成功。始终检查失败:
$result = mysql_query($sql) or die(mysql_error()); -
如果有的话,你看到了什么错误?如果没有,请尝试打开
error_reporting -
上传到服务器时,您是否将用户名和密码更改为服务器凭据?
-
实时 FTP 上的主机、用户名和密码真的正确吗?
-
@CodeGodie ,我打开错误报告并得到以下信息:“已弃用:mysql_connect(): mysql 扩展已弃用,将来将被删除:在 /home 中使用 mysqli 或 PDO 代替/.../public_html/team/myfile.php”。我还检查并仔细检查了我的服务器用户名和密码,一切都在那里。