Ahoj,
Resim ted malej ukol.. Mam formular kde mam tyto polozky
Jmeno:
Prijmeni:
Vek:
Tyto polozky se generuji pomoci javascriptu takze jich muze byt vice a tudiz jde o pole.. Rad bych se zeptal jak to pak ulozit do databaze? Nebo jaky je na to vhodny zpusob ktery bych mel pouzit? Ja jsem premyslel o tom ze bych to rozdelil podle nejakeho znaku? Takze by v db pak bylo:
Jmeno: Petr; Pavel;Jan ...
Prijmeni: Novak;Kanak;Kroupa
Vek: 20;22;23
Dekuji za kazdou radu..
Fórum › PHP
Formular

Vytvoř si prostě víc těch políček, pojmenuj všechna příjmení jako prijmeni a všechna jmena jako jmeno... Pak to již stačí prohnat funkcí foreach
foreach($_POST['prijmeni'] AS $prijmeni)
{
// to co chces provest s $prijmeni
}
Předpokládám že to budeš chtít uložit do MySQL
mysql_connect("server","uzivatel","heslo");
mysql_select_db("databaze");
$jmeno = mysql_real_escape_string(htmlspecialchars($_POST['jmeno']));
$prijmeni = mysql_real_escape_string(htmlspecialchars($_POST['prijmeni']));
if(!is_numeric($_POST['vek'])) { $vek = 0;}
mysql_query("INSERT INTO tabulka SET jmeno='$jmeno', prijmeni='$prijmeni', vek='$vek'");
To Ruda :
je NUTNÉ každý údaj - člověka, nebo co to ukládáš - ukládat zvlášť jako nový záznam.
žádné spojování do více buněk nedělej!
a jak to chceš ukládat, to už je celkem na tobě, protože záleží, jaký jména těm imputum vygeneruješ.
radím:
generuj jména nejak <input type="text" name="clovek[1][jmeno]" />
potom ti to php prevede automaticky na pole a udelas jen
foreach ($_POST['clovek'] as $clovek) {
mysql_query(....insert .... $clovek);
}
http://jan.skrasek.com – @hrachcz – webdeveloper
index.php (index.htm)
<form action="spracuj.php" method="post">
<input type="text" name="meno[1]" />
<input type="text" name="priezvisko[1]" />
<input type="text" name="vek[1]" />
<input type="text" name="meno[2]" />
<input type="text" name="priezvisko[2]" />
<input type="text" name="vek[2]" />
<input type="text" name="meno[3]" />
<input type="text" name="priezvisko[3]" />
<input type="text" name="vek[3]" />
<input type="submit">
spracuj.php
<?php
if (($link = mysql_connect("adresa","uzivatel","heslo"))and(mysql_select_db("nazov_databazi")) {
for ($i = 1; $i <= count($_POST[meno]); $i++) {
$meno = mysql_real_escape_string(htmlspecialchars($_POST[meno][$i]));
$priezvisko = mysql_real_escape_string(htmlspecialchars($_POST[priezvisko][$i]));
if(is_numeric($_POST[vek][$i])) { $vek = $_POST[vek][$i]; } else { $vek = ""; }
mysql_query("INSERT INTO nazov_tabulky VALUES (meno='".$meno."', priezvisko='".$priezvisko."', vek='".$vek."'");
}
echo "Bolo vlozenych <b>".count($_POST[meno])."</b>" záznamov.";
mysql_close($link);
} else {
echo "Chyba pripojenia k DB !";
}
Zdrojak predpoklada ze budu vzdy zadane vsetky udaje. Pocet "inputov" si mozes samozrejme rozsirit, ale vzdy pridavaj cislo naviac v hranatej zatvorke...
Pisane z hlavy, nezarucujem funkcnost. Ak by bol daky problem, napis.

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 108 hostů
Podobná vlákna
Formulář — založil KiRoS
Formular — založil alan158
Formulář — založil Martin Beseda
Formulář — založil KiRoS
Moderátoři diskuze