Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Edycja danych w bazie MySQL przez formularz
Forum PHP.pl > Forum > Przedszkole
fastlone
Witam.
Mam przykładowo bazę danych 123, w niej tabele admins. Mam w niej komorki auth, password, access, flags i days.
Czy jest możliwość stworzenia skryptu PHP, który pozwalałby na dodawanie, usuwanie i edycję rekordów wpisanych do tej tabeli?
wookieb
Nie nie istnieje taka możliwość. Tutaj możesz użyć c++.
fastlone
Jeśli to jest niemożliwe, to czemu pewne skrypty PHP mają to? np. AMXBans ma możliwość dodawania rekordów, edycji bądź usuwania ich. A przeglądając kod źródłowy jest tam tylko PHP.
  1. <?php
  2.  
  3. /*
  4.  *
  5.  * AMXBans, managing bans for Half-Life modifications
  6.  * Copyright ˆ 2009, www.amxbans.de
  7.  *
  8.  * mail : setoy@my-horizon.de
  9.  * ICQ : 226696015
  10.  *
  11.  * This file is part of AMXBans.
  12.  *
  13.  * AMXBans is free software; you can redistribute it and/or modify
  14.  * it under the terms of the GNU General Public License as published by
  15.  * the Free Software Foundation; either version 2 of the License, or
  16.  * (at your option) any later version.
  17.  *
  18.  * AMXBans is distributed in the hope that it will be useful,
  19.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21.  * GNU General Public License for more details.
  22.  *
  23.  * You should have received a copy of the GNU General Public License
  24.  * along with AMXBans; if not, write to the Free Software
  25.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26.  *
  27.  */
  28.  
  29. // Start session
  30.  
  31. // Require basic site files
  32.  
  33. require("../include/config.inc.php");
  34.  
  35. if ($config->error_handler == "enabled") {
  36. include("$config->error_handler_path");
  37. }
  38. include("$config->path_root/include/functions.lang.php");
  39. include("$config->path_root/include/accesscontrol.inc.php");
  40. //include("$config->path_root/include/class_hlsi.php");
  41.  
  42. if(($_SESSION['amxadmins_edit'] != "yes") || ($config->admin_management != "enabled")) {
  43. echo lang("_NOACCESS");
  44. exit();
  45. }
  46.  
  47. //display_post_get();
  48.  
  49. if ((isset($_POST['action'])) && ($_POST['action'] == "apply")) {
  50.  
  51. foreach($_POST as $key => $value) {
  52. if (is_numeric($key)) {
  53.  
  54. // check if admin was active on this server...
  55. $resource = mysql_query("SELECT COUNT(admin_id) AS get_adm FROM $config->admins_servers WHERE admin_id = '$key' AND server_id = '".$_POST['server_id']."'") or die (mysql_error());
  56. $result = mysql_fetch_object($resource);
  57.  
  58. if ($result->get_adm == 0) {
  59. if($value == "on") {
  60. $resource = mysql_query("INSERT INTO $config->admins_servers VALUES('$key', '".$_POST['server_id']."')") or die (mysql_error());
  61.  
  62. $now = date("U");
  63. $add_log = mysql_query("INSERT INTO $config->logs (timestamp, ip, username, action, remarks) VALUES ('$now', '".$_SERVER['REMOTE_ADDR']."', '".$_SESSION['uid']."', 'serveradmins', 'Assigned AdminID $key to ServerID ".$_POST['server_id']."')") or die (mysql_error());
  64. }
  65. } else if ($result->get_adm == 1) {
  66. if($value == "off") {
  67. $resource = mysql_query("DELETE FROM $config->admins_servers WHERE admin_id = '$key' AND server_id = '".$_POST['server_id']."'") or die (mysql_error());
  68.  
  69. $now = date("U");
  70. $add_log = mysql_query("INSERT INTO $config->logs (timestamp, ip, username, action, remarks) VALUES ('$now', '".$_SERVER['REMOTE_ADDR']."', '".$_SESSION['uid']."', 'serveradmins', 'Removed AdminID $key from ServerID ".$_POST['server_id']."')") or die (mysql_error());
  71. }
  72. } else {
  73. echo "Duplicate entry found?";
  74. }
  75. }
  76. }
  77. }
  78.  
  79. // get a list of servers...
  80. $resource = mysql_query("SELECT id, hostname, amxban_version FROM $config->servers ORDER BY hostname ASC") or die (mysql_error());
  81.  
  82. while($result = mysql_fetch_object($resource)) {
  83.  
  84. $checkplug = explode ("_", $result->amxban_version);
  85. $amx_version = $checkplug['0'];
  86.  
  87. //echo "<h2>$amx_version</h2>";
  88.  
  89. // Asign variables to the array used in the template
  90. $server_info = array(
  91. "id" => $result->id,
  92. "hostname" => $result->hostname,
  93. "amxversion" => $amx_version
  94. );
  95.  
  96. $server_array[] = $server_info;
  97. }
  98.  
  99. if ( isset($_POST['server_id']) && $_POST['server_id'] != "xxx")
  100. {
  101. $serverid = $_POST['server_id'];
  102.  
  103. // get a list of admins for this server
  104. $resource2 = mysql_query("SELECT admin_id FROM $config->admins_servers WHERE server_id = '$serverid'") or die (mysql_error());
  105. $these_admins = array();
  106.  
  107. while($result2 = mysql_fetch_object($resource2)) {
  108.  
  109. //get their user- and nicknames too
  110. $resource2a = mysql_query("SELECT username, nickname FROM $config->amxadmins WHERE id = '$result2->admin_id' ORDER BY access DESC") or die (mysql_error());
  111.  
  112. while($result2a = mysql_fetch_object($resource2a)) {
  113. $admin_info = array(
  114. "id" => $result2->admin_id,
  115. "username" => $result2a->username,
  116. "nickname" => $result2a->nickname
  117. );
  118. }
  119. $these_admins[] = $admin_info;
  120. }
  121.  
  122. $resource3 = mysql_query("SELECT admin_id FROM $config->admins_servers WHERE server_id = '$serverid'") or die (mysql_error());
  123. $these_adminids = array();
  124.  
  125. while($result3 = mysql_fetch_object($resource3)) {
  126. $these_adminids[] = $result3->admin_id;
  127. }
  128.  
  129. // get a list of all adminIDs (but not those who are active for this server...
  130. $resource3 = mysql_query("SELECT id, username, nickname FROM $config->amxadmins WHERE username IS NOT NULL AND username != '' ORDER BY id ASC") or die (mysql_error());
  131. $all_admins = array();
  132.  
  133. while($result3 = mysql_fetch_object($resource3)) {
  134.  
  135. if(in_array($result3->id, $these_adminids)) {
  136. $admin_info = array(
  137. "id" => $result3->id,
  138. "username" => $result3->username,
  139. "nickname" => $result3->nickname,
  140. "checked" => 1
  141. );
  142. } else {
  143. $admin_info = array(
  144. "id" => $result3->id,
  145. "username" => $result3->username,
  146. "nickname" => $result3->nickname,
  147. "checked" => 0
  148. );
  149. }
  150.  
  151. $all_admins[] = $admin_info;
  152. }
  153. }
  154.  
  155. /*
  156.  *
  157.  * Template parsing
  158.  *
  159.  */
  160.  
  161. $title = "Serveradmins";
  162.  
  163. // Section
  164. $section = "server_admins";
  165.  
  166. $smarty = new dynamicPage;
  167.  
  168. $smarty->assign("meta","");
  169. $smarty->assign("title",$title);
  170. $smarty->assign("section",$section);
  171. $smarty->assign("dir",$config->document_root);
  172. $smarty->assign("this", $_SERVER['PHP_SELF']);
  173. $smarty->assign("submitted",get_post('submitted'));
  174.  
  175. $smarty->assign("thisserver", isset($serverid) ? $serverid : NULL);
  176. $smarty->assign("servers", isset($server_array) ? $server_array : NULL);
  177. $smarty->assign("all_admins", isset($all_admins) ? $all_admins : NULL);
  178. $smarty->assign("these_admins", isset($these_admins) ? $these_admins : NULL);
  179.  
  180. $smarty->display('main_header.tpl');
  181. $smarty->display('server_admins.tpl');
  182. $smarty->display('main_footer.tpl');
  183.  
  184. ?>
wookieb
No bo oczywiście że jest możliwość tylko, że zadajesz tak głupie pytanie że tak naprawdę powinno wylecieć z tego forum. Nie zrozumiałeś ironii.
A skoro znasz odpowiedź na to pytanie to po co się pytasz?
fastlone
Pytam się, bo w PHP jestem zielony, a potrzebuję takiego skryptu. Nie umiem przerobić żadnego znanego mi kodu.
wookieb
Szukajcie a znajdziecie.
http://pl.php.net/manual/en/language.variables.external.php
A jak nie umiesz edytować rekordów to kurs sql i jazda.
fastlone
Umiem to wszystko zrobić przez PHPMyAdmin'a, lecz inne osoby, które się zajmują ustalaniem listy, która jest zawarta w tej tabeli, nie umieją tego.
W tym celu potrzebuję tego skryptu. Czy mógłby takie coś ktoś dla mnie zrobić? Nie zależy mi na estetyce.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.