Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Dodawanie tabel i danych do tabel
piotrekba88
post
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 7.08.2013

Ostrzeżenie: (0%)
-----


Witam,

Mam pytanie odnośnie dodawania tabel i danych do tabel poprzez formularz PHP.
Potrzebuje tego typu sposobu dodawania ponieważ z formularza będą pobierane dane takie jak prefix dla tabeli czy nazwa strony. Będzie około 10 zmiennych, które po wpisaniu wypełnią odpowiednie pola w zapytaniu do bazy i zostaną "zaimportowane" do mojej bazy danych.

Mój "skrypcik", którego koda dałem niżej niestety nie działa. Tworzy tabele ale niestety kod dodający dane do tabeli nie działa (IMG:style_emoticons/default/sad.gif)

Pomoże ktoś?


  1. <?php
  2.  
  3. // podłączamy plik connection.php
  4.  
  5. require "connection.php";
  6.  
  7. // wywołujemy funkcję connection()
  8.  
  9. connection();
  10.  
  11. ?>
  12.  
  13.  
  14. <form action="sql.php" method="post">
  15. Prefix:<br />
  16. <input type="text" name="prefix" /><br />
  17. <input type="submit" value="dodaj" />
  18. </form>
  19.  
  20.  
  21.  
  22. <?php
  23.  
  24. // odbieramy dane z formularza
  25. $prefix = $_POST['prefix'];
  26.  
  27. if($prefix) {
  28.  
  29. // dodajemy tabele do bazy
  30.  
  31. $ins = @mysql_query("CREATE TABLE ".$prefix."_assets (
  32. `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
  33. `parent_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Nested set parent.',
  34. `lft` int(11) NOT NULL DEFAULT '0' COMMENT 'Nested set lft.',
  35. `rgt` int(11) NOT NULL DEFAULT '0' COMMENT 'Nested set rgt.',
  36. `level` int(10) unsigned NOT NULL COMMENT 'The cached level in the nested tree.',
  37. `name` varchar(50) NOT NULL COMMENT 'The unique name for the asset.\n',
  38. `title` varchar(100) NOT NULL COMMENT 'The descriptive title for the asset.',
  39. `rules` varchar(5120) NOT NULL COMMENT 'JSON encoded access control.',
  40. PRIMARY KEY (`id`),
  41. UNIQUE KEY `idx_asset_name` (`name`),
  42. KEY `idx_lft_rgt` (`lft`,`rgt`),
  43. KEY `idx_parent_id` (`parent_id`)
  44. ) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8 AUTO_INCREMENT=96 ;" );
  45.  
  46. @mysql_query("INSERT INTO ".$prefix."_categories VALUES (1, 0, 0, 0, 7, 0, '', 'system', 'ROOT', 0x726f6f74, '', '', 1, 0, '0000-00-00 00:00:00', 1, '{}', '', '', '', 42, '2011-01-01 00:00:01', 0, '0000-00-00 00:00:00', 0, '*', 1);
  47. INSERT INTO ".$prefix."_categories VALUES (2, 27, 1, 1, 2, 1, 'uncategorised', 'com_content', 'Uncategorised', 0x756e63617465676f7269736564, '', '', 1, 0, '0000-00-00 00:00:00', 1, '{"target":"","image":""}', '', '', '{"page_title":"","author":"","robots":""}', 42, '2011-01-01 00:00:01', 0, '0000-00-00 00:00:00', 2, '*', 1);
  48. INSERT INTO ".$prefix."_categorie` VALUES (4, 29, 1, 3, 4, 1, 'uncategorised', 'com_contact', 'Uncategorised', 0x756e63617465676f7269736564, '', '', 1, 0, '0000-00-00 00:00:00', 1, '{"target":"","image":""}', '', '', '{"page_title":"","author":"","robots":""}', 42, '2011-01-01 00:00:01', 0, '0000-00-00 00:00:00', 0, '*', 1);
  49. INSERT INTO ".$prefix."_categories VALUES (7, 32, 1, 5, 6, 1, 'uncategorised', 'com_users', 'Uncategorised', 0x756e63617465676f7269736564, '', '', 1, 0, '0000-00-00 00:00:00', 1, '{"target":"","image":""}', '', '', '{"page_title":"","author":"","robots":""}', 42, '2011-01-01 00:00:01', 0, '0000-00-00 00:00:00', 0, '*', 1);
  50. ")
  51.  
  52.  
  53.  
  54. if($ins) echo "Rekord został dodany poprawnie";
  55.  
  56. else echo "Błąd nie udało się dodać nowego rekordu";
  57.  
  58.  
  59.  
  60. }
  61.  
  62. ?>


Ten post edytował piotrekba88 22.08.2013, 08:59:57
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 - 14:41