Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Jak zaaktualizować wszystkie rekordy?
woxala123
post
Post #1





Grupa: Zarejestrowani
Postów: 361
Pomógł: 12
Dołączył: 9.01.2010

Ostrzeżenie: (10%)
X----


Witam.
Stworzyłem sobie formularz który wyświetla dane użytkowników. Chcę by po zmianie w polach i naciśnięciu wyslij aktualizował wszystkie rekordy. Jak na razie aktualizuje ostatni rekord. Myślę że błąd robię w zapytaniu update. Prosze o pomoc.

  1.  
  2. <?php require_once('../Connections/myconn.php'); ?>
  3. <?php
  4. if (!function_exists("GetSQLValueString")) {
  5. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  6. {
  7. if (PHP_VERSION < 6) {
  8. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  9. }
  10.  
  11. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  12.  
  13. switch ($theType) {
  14. case "text":
  15. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  16. break;
  17. case "long":
  18. case "int":
  19. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  20. break;
  21. case "double":
  22. $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  23. break;
  24. case "date":
  25. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  26. break;
  27. case "defined":
  28. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  29. break;
  30. }
  31. return $theValue;
  32. }
  33. }
  34.  
  35. $editFormAction = $_SERVER['PHP_SELF'];
  36. if (isset($_SERVER['QUERY_STRING'])) {
  37. $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  38. }
  39.  
  40. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1"))
  41. {
  42. $updateSQL = sprintf("UPDATE admin SET name=%s, email=%s WHERE id=%s",
  43. GetSQLValueString($_POST['name'], "text"),
  44. GetSQLValueString($_POST['email'], "text"),
  45. GetSQLValueString($_POST['id'], "int"));
  46.  
  47. mysql_select_db($database_myconn, $myconn);
  48. $Result1 = mysql_query($updateSQL, $myconn) or die(mysql_error());
  49.  
  50. $updateGoTo = "reba.php";
  51. if (isset($_SERVER['QUERY_STRING'])) {
  52. $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
  53. $updateGoTo .= $_SERVER['QUERY_STRING'];
  54. }
  55. header(sprintf("Location: %s", $updateGoTo));
  56. }
  57.  
  58. mysql_select_db($database_myconn, $myconn);
  59. $query_Recordset1 = "SELECT * FROM `admin`";
  60. $Recordset1 = mysql_query($query_Recordset1, $myconn) or die(mysql_error());
  61. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  62. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  63. ?>
  64. <form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  65. <p>&nbsp;</p>
  66. <table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
  67. <tr>
  68. <td align="center"><strong>Id</strong></td>
  69. <td align="center"><strong>Name</strong></td>
  70. <td align="center"><strong>Email</strong></td>
  71. </tr>
  72. <?php do { ?>
  73. <tr>
  74. <td><label for="id"></label>
  75. <input name="id" type="text" id="id" value="<?php echo $row_Recordset1['id']; ?>" size="15" maxlength="15"></td>
  76. <td><label for="name"></label>
  77. <input name="name" type="text" id="name" value="<?php echo $row_Recordset1['name']; ?>" size="15" maxlength="15"></td>
  78. <td><label for="email"></label>
  79. <input name="email" type="text" id="email" value="<?php echo $row_Recordset1['email']; ?>" size="15" maxlength="15"></td>
  80. </tr>
  81. <input name="id" type="hidden" id="id" value="<?php echo $row_Recordset1['id']; ?>">
  82. <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  83. </table>
  84. <p>
  85. <input type="submit" name="button" id="button" value="Wyślij">
  86. </p>
  87. <p>&nbsp;</p>
  88. <input type="hidden" name="MM_update" value="form1">
  89. </form>
  90. <?php
  91. mysql_free_result($Recordset1);
  92. ?>
  93.  
  94.  


Ten post edytował woxala123 14.08.2013, 09:33:14
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 23:20