Hi all, I am facing a problem here which would like to seek helps from the experts.

I have a table which is able to display all the data in text field format from the database in a table. The users are able to edit the displayed data.

I would like to create a link/button which called "update" which will update all the edited data. In the code, I have created a hyperlink "http://project/Project/update.php" which will update all the edited data, once the user click on it. However, I am not sure how to do it. Do I need to use $_SESSION ?

The following is my codes:

<html>
<script language="javascript" >
<!-- hide
function submitRequest(id) {
document.forms[id].submit();
}
// end hide -->
</script>

<script language="JavaScript">
  function removeAlignment(id){
   document.getElementById("ProjectName_"+id).removeAttribute("readonly",0);
	 document.getElementById("DeviceType_"+id).removeAttribute("readonly",0);
	 document.getElementById("ProjectType_"+id).removeAttribute("readonly",0);
  }
</script>

<body>
	<title>ADC Project Funnel</title>

<?php

$counter=1;
$counter2=1; 
$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'");
$result2 = mysql_query("SELECT * FROM project where status='Future'");

?>

<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: 12" align="center"><b><font size="1" face="Arial">No</font></b></td>
    <td width="78" bgcolor="steelblue" height="15" style="font-size: 12" align="center"><b><font size="1" face="Arial">Project
      Name</font></b></td>
    <td width="72" bgcolor="steelblue" height="15" style="font-size: 12" align="center"><b><font size="1" face="Arial">Device Type</font></b></td>
    <td width="67" bgcolor="steelblue" height="15" style="font-size: 12" align="center"><b><font size="1" face="Arial">Status</font></b></td>
    <td width="67" bgcolor="steelblue" height="15" style="font-size: 12" align="center"><b><font size="1" 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 -->
  <?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>
    </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" height="15" bgcolor="#AFEEEE"><font face="Arial" size="1.9" >Future Project Assignment</font></td>
  </tr> 

 <?php 
    while ($row=mysql_fetch_array($result2)){
  ?>
    <tr>
    <form name="form1" action="submitAction.php" method="post">
    <td width="20" style="font-size: 13" align="center"><?php echo $counter2; ?></td>
    <td 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 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 width="67" style="font-size: 13">
    <select name="action" style="width:100%" onchange="submitRequest(<?php echo $i; ?>);">
    <option value=>Future </option>
    <option value="<?php echo $row['ProjectName'];?>">Ongoing</option>
    <option value="<?php echo $row['Flag1'];?>">Cancel</option>
    </select>								
    </form>
    </td>
    <td width="64" ><input type="button" value="Edit" style="width:100%" onclick="removeAlignment(<?php echo $i; ?>);"></font></td>
    </tr>
  
  <?php 
  $i++;
  $counter2++;
  }
  ?>
  
 </table>

<br/>
<table border="0" align="center" cellpadding="0" cellspacing="10">
<tr>
       <td valign="middle"><a href="http://project/Project/update.php">Update</a></td>

</tr>
</table>

</body>
</html>

Thanks guys! :)

Your 'update' link needs to be it's own form. You have 'form1', so make this 'refreshForm' or the like. Once you've create the form, the form action needs to be something like:

action="update.php?update=true"

That is, if the file is named 'update.php'...use whatever file name you've given.

Then, you'll need to add a section to the top section of PHP code that actually performs the update that you need if the $_GET option is 'true', such as:

if ($_GET['update'] == 'true') {

    $newname    = $_POST['name'];
    $newemail   = $_POST['email'];
    $newsubject = mysql_real_escape_string($_POST['subject']);


    // Do your MySQL stuff here based on what you want changed and the $_POST
    // vars that you've created.
}

// Continue with the rest of the normal code.
?>

Make sense?