php - $_post Problem (How to pass the value of $_post) -
i have following code works well.
the code display data database in input text field format. user able edit , update details clicking update button @ end of each row update specific row.
instead of clicking update buttons 1 one (if user wants edit , update more 1 row), create hyperlink update data @ once.
the problem dunno how pass value of $_post "update.php" since have
<form name="form1" action="submitaction.php" method="post">
i not sure possible so. or there other alternative ways?
<html> <script language="javascript" > <!-- hide function submitrequest(id) { document.forms[id].submit(); } // end hide --> </script> <!-- javasript (onclick) remove 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 , accessing database $con = mysql_connect("localhost","root",""); if (!$con) { die('could not connect: ' . mysql_error()); } mysql_select_db("project", $con); $result = mysql_query("select * project 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 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>
make 1 form tag - not individual form tag each row.
next change:
<select name="action" onchange="submitrequest(<?php echo $i; ?>);">
to:
<select name="action[<php echo $i; ?>]" onchange="submitrequest(<?php echo $i; ?>);">
(it's better use primary key database instead of $i counter, don't is.)
also has not been necessary do:
<!-- hide // end hide -->
for 10 years already, should stop including that.
Comments
Post a Comment