Posted By

ialmonacid on 08/22/12


Tagged

php update


Versions (?)

Update MySQL PHP


 / Published in: PHP
 

update php a mysql

  1. <?php
  2.  
  3. $host="localhost";
  4. $username="asaadadasdd";
  5. $password="adsdfagdfag";
  6. $db_name="sagsdfagsfags_base";
  7. $tbl_name="gasfafsdafdsaf_tabla"; XD
  8.  
  9.  
  10. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  11. mysql_select_db("$db_name")or die("cannot select DB");
  12.  
  13. $sql="SELECT * FROM $tbl_name order by ID_Aviso desc limit 100";
  14. $result=mysql_query($sql);
  15.  
  16. $count=mysql_num_rows($result);
  17. ?>
  18. <form name="form1" method="post" action="">
  19. <table width="1000" border="0" cellspacing="1" cellpadding="0">
  20. <tr>
  21. <td align="center"><strong>Id</strong></td>
  22. <td align="center"><strong>Name</strong></td>
  23. <td align="center"><strong>Lastname</strong></td>
  24. <td align="center"><strong>Email</strong></td>
  25. </tr>
  26.  
  27. <?php
  28. while($rows=mysql_fetch_array($result)){
  29. ?>
  30.  
  31. <tr>
  32. <td align="center">
  33. <? $ID_Aviso[]=$rows['ID_Aviso']; ?><? echo $rows['ID_Aviso']; ?>
  34. </td>
  35. <td align="center">
  36. <input name="texto[<? echo $rows ['ID_Aviso'] ?>]" type="text" id="texto" value="<? echo $rows['texto']; ?>" size="100">
  37. <!-- ESTO ERA ASÍ ORIGINALMENTE <input name="texto[]" type="text" id="texto" value="<? echo $rows['texto']; ?>" size="100"> -->
  38. </td>
  39. <td align="center">
  40. <input name="telefono[<? echo $rows ['ID_Aviso'] ?>]" type="text" id="lastname" value="<? echo $rows['telefono']; ?>">
  41. </td>
  42. <td align="center">
  43. <input name="edicion_numero[<? echo $rows ['ID_Aviso'] ?>]" type="text" id="edicion_numero" value="<? echo $rows['edicion_numero']; ?>">
  44. </td>
  45. </tr>
  46.  
  47. <?php
  48.  
  49. }
  50. ?>
  51.  
  52. <tr>
  53. <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
  54. </tr>
  55. </table>
  56. </form>
  57.  
  58. <?php
  59.  
  60. if($Submit){
  61. for($i=0;$i<$count;$i++){
  62. $sql1="UPDATE $nqn_avisos SET texto='$texto[$i]', telefono='$telefono[$i]', edicion_numero='$edicion_numero[$i]' WHERE ID_Aviso='$ID_Aviso[$i]'";
  63. $result1=mysql_query($sql1);
  64. }
  65. }
  66.  
  67. if($result1){
  68. header("location:edit.php");
  69. }
  70. ?>

Report this snippet   <

You need to login to post a comment.