我一直在研究一个待办事项列表,它使具有管理员权限的人能够从表单中编辑/更新公司内所有员工的多个百分比。发送的数据可能介于 50 到 200 个条目之间,并且会一次性全部更新。
我一直面临的问题是,表单和页面在我的 XAMPP 本地机器上工作得非常好,并且可以通过更新的 Action 运行,但是,一旦我将它上传到实时 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>");
}
?>
最佳答案
如果你能确保在线服务器上的配置主机、用户和密码数据库是正确的。
然后根据我的阅读,您必须尝试将您的代码“mysql_”更改为“mysqli_”
例子:
mysql_connect("$host", "$username", "$password")or die("cannot connect");
到
mysqli_connect("$host", "$username", "$password")or die("cannot connect");
http://www.w3schools.com/php/php_ref_mysqli.asp
我的答案会根据你的评论而改变,因为我不知道你那里的东西。
关于php - MySQL PHP 表更新/POST 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32074347/