Hi guys, I have the following code which works well.
The code is to display all the data from the database in input text field format. User is able to edit and update the details by clicking the update button at the end of each row to update the specific row.
Instead of clicking the update button one by one (if user want to edit and update more than one row), now I would like to create a hyperlink which will update ALL the data at once.
The problem now is I dunno how to pass the value of $_post to the "update.php" since I already have
<form name="form1" action="submitAction.php" method="post">
I am not sure is it possible to do so. Or is there any other alternative ways?
Thanks in advanced! :)
<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>