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ś?
<?php
// podłączamy plik connection.php
require "connection.php";
// wywołujemy funkcję connection()
connection();
?>
<form action="sql.php" method="post">
Prefix:<br />
<input type="text" name="prefix" /><br />
<input type="submit" value="dodaj" />
</form>
<?php
// odbieramy dane z formularza
$prefix = $_POST['prefix'];
if($prefix) {
// dodajemy tabele do bazy
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`parent_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Nested set parent.',
`lft` int(11) NOT NULL DEFAULT '0' COMMENT 'Nested set lft.',
`rgt` int(11) NOT NULL DEFAULT '0' COMMENT 'Nested set rgt.',
`level` int(10) unsigned NOT NULL COMMENT 'The cached level in the nested tree.',
`name` varchar(50) NOT NULL COMMENT 'The unique name for the asset.\n',
`title` varchar(100) NOT NULL COMMENT 'The descriptive title for the asset.',
`rules` varchar(5120) NOT NULL COMMENT 'JSON encoded access control.',
PRIMARY KEY (`id`),
UNIQUE KEY `idx_asset_name` (`name`),
KEY `idx_lft_rgt` (`lft`,`rgt`),
KEY `idx_parent_id` (`parent_id`)
) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8 AUTO_INCREMENT=96 ;" );
@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); 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);
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);
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);
")
if($ins) echo "Rekord został dodany poprawnie";
else echo "Błąd nie udało się dodać nowego rekordu";
}
?>
Ten post edytował piotrekba88 22.08.2013, 08:59:57