I wan`t to save a form in my Database for a Gantt Diagramm, but i have to make a brake after 4 input fields. Then i start with a new row.
Here is my SQL Code for the table:
CREATE TABLE `tplan` (
`id` int(11) NOT NULL,
`text` varchar(255) NOT NULL,
`start_date` datetime NOT NULL,
`dauer` int(11) NOT NULL,
`parent` int(11) NOT NULL,
`farbe` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Here is the a Part of the Form, this two "form-row" i have 10 times:
<div class="form-row">
<div class="col">
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroupPrepend2" data-toggle="tooltip" data-placement="top" title="Projekt Nr."><i class="fas fa-hashtag"></i></span>
</div>
<input type="text" class="form-control" id="projektnr_anz" name="pjs[]" value="<?php echo $_POST["projektnr"]; ?>" required>
</div>
</div>
</div>
<div class="col-4">
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroupPrepend3" data-toggle="tooltip" data-placement="top" title="Projekt Start"><i class="far fa-calendar-alt"></i></i></span>
</div>
<input type="text" class="form-control" id="lt" name="pjs[]" required>
<input type="hidden" name="pjs[]" value="1">
<input type="hidden" name="pjs[]" value="0">
<input type="hidden" name="pjs[]" value="#A4A4A4">
</div>
</div>
</div>
</div>
Here is my try with foreach loop:
// DB Eintrag erstellen
if(isset($_POST["speichern"])){
// Schleife um alle Daten aus Formular einzutragen
foreach($_POST["pjs"] as $value)
{
if( $value == 'speichern' ){
break;
} else {
// Wenn gesetzt dann Insert der DB
$speichern_tp = "INSERT INTO tplan (text, start_date, dauer, parent, farbe) VALUES ('" . $_POST["datum"] . "')";
$querys_tp = mysqli_query($conn, $speichern_tp) or die(mysqli_error());
echo $value."</br>";
}
}
}
In the table of the DB i have to put in one row booth input fields in the column "dauer" and "star_date" in the column "text" i will put a fixed text from an Array. In the wor "parent" comes the id from the last row - a fix number and "farbe" is a Array with fix codes.
But i have no idea how i can handle the input.
Thank`s for Help.
source https://stackoverflow.com/questions/67892661/save-a-form-in-steps-in-mysql-database
No comments:
Post a Comment