我有下面的代碼效果很好。
的代碼來顯示從在輸入文本字段格式的數據庫中的所有數據。用戶可以通過單擊每行末尾的更新按鈕來更新特定行,從而編輯和更新詳細信息。
而不是點擊更新按鈕,一個接一個的(如果用戶希望編輯和更新多行),現在我想創建,將同時更新所有數據的超鏈接。
現在的問題是我不知道怎麼的$ _POST值傳遞給了「update.php」因爲我已經有
<form name="form1" action="submitAction.php" method="post">
我不知道是否有可能這樣做。或者還有其他方法嗎?
<html>
<script language="javascript" >
<!-- hide
function submitRequest(id) {
document.forms[id].submit();
}
// end hide -->
</script>
<!-- The Javasript (Onclick) to Remove the Readonly Attribute-->
<script language="JavaScript">
function removeAlignment(id){
document.getElementById("ProjectName_"+id).removeAttribute("readonly",0);
document.getElementById("DeviceType_"+id).removeAttribute("readonly",0);
}
</script>
<body>
<?php
$counter=1;
//Connecting and Accessing the Database
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Project", $con);
$result = mysql_query("SELECT * FROM Project where status='Ongoing'");
?>
<p><h2 align="center">ADC Project Funnel</h2></p>
<table border="1" bordercolor="lavender" cellspacing="0" cellpadding="0">
<tr>
<td width="20" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">No</font></b></td>
<td width="78" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">Project
Name</font></b></td>
<td width="72" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">Device Type</font></b></td>
<td width="67" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">Status</font></b></td>
<td width="67" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial"></font></b></td>
</tr>
<tr>
<td colspan="15" height="15" bgcolor="#AFEEEE"><font face="Arial" size="1.9">Current Project Assignment</font></td>
</tr>
<!-- Records from the database (Current Project Assignment) -->
<?php
$i = 0;
while ($row=mysql_fetch_array($result)){
?>
<tr>
<form name="form1" action="submitAction.php" method="post">
<td height="5" width="20" align="center" style="font-size: 13" valign="middle"><?php echo $counter; ?></td>
<td height="5" width="72" ><input type="text" autocomplete=off readonly="readonly" id="ProjectName_<?php echo $i; ?>" name="ProjectName<?php echo $row['No'];?>" value="<?php echo $row['ProjectName'];?>" size="20" style="font-size: 10"></font></td>
<td height="5" width="72" ><input type="text" autocomplete=off readonly="readonly" id="DeviceType_<?php echo $i; ?>" name="DeviceType<?php echo $row['No'];?>" value="<?php echo $row['DeviceType'];?>" size="15" style="font-size: 10"></font></td>
<td height="5" width="67" style="font-size: 13">
<select name="action" onchange="submitRequest(<?php echo $i; ?>);">
<option value=>Ongoing </option>
<option value="<?php echo $row['ProjectName'];?>">Complete</option>
<option value="<?php echo $row['Flag2'];?>">Future</option>
<option value="<?php echo $row['Flag1'];?>">Cancel</option>
<option value="<?php echo $row['No'];?>">Update</option>
<option value="<?php echo $row['Flag3'];?>">Delete</option>
</select>
</td>
<td height="5" width="64" ><input type="button" style="width:100%" value="Edit" onclick="removeAlignment(<?php echo $i; ?>);"></td>
</tr>
</form>
<?php
?>
<?php
$i++;
$counter++;
}
?>
<tr>
<td colspan="16" bgcolor="#AFEEEE"><font face="Arial" size="1.9">Add New Project Assignment</font></td>
</tr>
<!-- Add New Records -->
<tr>
<form action="project_insert.php" method="post">
<td width="20" ></td>
<td width="78" ><input type="text" autocomplete=off name="ProjectName" size="40" style="font-size: 10"></font></td>
<td width="72" ><input type="text" autocomplete=off name="DeviceType" size="15" style="font-size: 10"></font>
<td width="80" style="font-size: 13">
<select name="Status" style="width:100%">
<option value=Future>Future</option>
<option value=Ongoing>Ongoing</option>
</select>
</td>
<td>
<input type="Submit" style="width:100%"value="Add">
</td>
</form>
</tr>
</table>
<br/>
<table border="0" align="center" cellpadding="0" cellspacing="10">
<tr>
<td valign="middle"><a href="http://localhost/Project/update.php">update</a></td>
</tr>
</table>
<br/>
</body>
</html>
這不是做一個聰明的做法。例如搜索引擎傾向於訪問頁面上的每個*網址,這將導致它在訪問此頁面時更新所有內容。 – Ikke
是的,但在回辦公室或登錄頁面這不是一個問題 – Awea
它仍然是一個黑客,而不是在那裏'GET'請求意味着。它要求各種各樣的問題。使用'POST'請求執行有後果的操作。 – Ikke