web 2.0

How to use PHP & MySQL Edit/Update Multiple Rows Record

How to use PHP & MySQL Edit/Update Multiple Rows Record Learn PHP how to using PHP edit/update multiple record on mysql table.

ShotDev Focus:
- PHP & MySQL edit/update multiple record.

Example

php_mysql_multiple_edit1.php

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. $objConnect = mysql_connect("localhost","root","root"or die(mysql_error());  
  8. $objDB = mysql_select_db("mydatabase");  
  9.   
  10. //*** Update Condition ***//  
  11. if($_GET["Action"] == "Save")  
  12. {  
  13. for($i=1;$i<=$_POST["hdnLine"];$i++)  
  14. {  
  15. $strSQL = "UPDATE customer SET ";  
  16. $strSQL .="CustomerID = '".$_POST["txtCustomerID$i"]."' ";  
  17. $strSQL .=",Name = '".$_POST["txtName$i"]."' ";  
  18. $strSQL .=",Email = '".$_POST["txtEmail$i"]."' ";  
  19. $strSQL .=",CountryCode = '".$_POST["txtCountryCode$i"]."' ";  
  20. $strSQL .=",Budget = '".$_POST["txtBudget$i"]."' ";  
  21. $strSQL .=",Used = '".$_POST["txtUsed$i"]."' ";  
  22. $strSQL .="WHERE CustomerID = '".$_POST["hdnCustomerID$i"]."' ";  
  23. $objQuery = mysql_query($strSQL);  
  24. }  
  25. //header("location:$_SERVER[PHP_SELF]");  
  26. //exit();  
  27. }  
  28.   
  29. $strSQL = "SELECT * FROM customer ORDER BY CustomerID ASC";  
  30. $objQuery = mysql_query($strSQLor die ("Error Query [".$strSQL."]");  
  31. ?>  
  32. <form name="frmMain" method="post" action="php_mysql_multiple_edit1.php?Action=Save">  
  33. <table width="600" border="1">  
  34. <tr>  
  35. <th width="91"> <div align="center">CustomerID </div></th>  
  36. <th width="98"> <div align="center">Name </div></th>  
  37. <th width="198"> <div align="center">Email </div></th>  
  38. <th width="97"> <div align="center">CountryCode </div></th>  
  39. <th width="59"> <div align="center">Budget </div></th>  
  40. <th width="71"> <div align="center">Used </div></th>  
  41. </tr>  
  42. <?  
  43. $i =0;  
  44. while($objResult = mysql_fetch_array($objQuery))  
  45. {  
  46. $i = $i + 1;  
  47. ?>  
  48. <tr>  
  49. <td><div align="center">  
  50. <input type="hidden" name="hdnCustomerID<?=$i;?>" size="5" value="<?=$objResult["CustomerID"];?>">  
  51. <input type="text" name="txtCustomerID<?=$i;?>" size="5" value="<?=$objResult["CustomerID"];?>">  
  52. </div></td>  
  53. <td><input type="text" name="txtName<?=$i;?>" size="20" value="<?=$objResult["Name"];?>"></td>  
  54. <td><input type="text" name="txtEmail<?=$i;?>" size="20" value="<?=$objResult["Email"];?>"></td>  
  55. <td><div align="center"><input type="text" name="txtCountryCode<?=$i;?>" size="2" value="<?=$objResult["CountryCode"];?>"></div></td>  
  56. <td align="right"><input type="text" name="txtBudget<?=$i;?>" size="5" value="<?=$objResult["Budget"];?>"></td>  
  57. <td align="right"><input type="text" name="txtUsed<?=$i;?>" size="5" value="<?=$objResult["Used"];?>"></td>  
  58. </tr>  
  59. <?  
  60. }  
  61. ?>  
  62. </table>  
  63. <input type="submit" name="submit" value="submit">  
  64. <input type="hidden" name="hdnLine" value="<?=$i;?>">  
  65. </form>  
  66. <?  
  67. mysql_close($objConnect);  
  68. ?>  
  69. </body>  
  70. </html>  

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php_mysql_multiple_edit1.php

Screenshot

PHP MySQL Edit/Update Multiple Record
.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.