Answer the question
In order to leave comments, you need to log in
How to add data to database from select?
I have two inputs from which I add data to the database in this way
Add form
<form action="" method="post">
<div class="form-group">
<small>Title</small>
<input type="text" class="form-control" name="name" value="" placeholder="Name">
</div>
<div class="form-group">
<small>Url</small>
<input type="text" class="form-control" name="url" value="" placeholder="Url">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" name="add" class="btn btn-primary">Save</button>
</div>
</form>
$title = $_POST['name'];
$url = $_POST['url'];
$get_id_type = $_GET['id'];
if (isset($_POST['add'])) {
$sql = ("INSERT INTO `xf_type` (`title`, `url`) VALUES (?,?)");
$query1 = $pdo->prepare($sql);
$query1->execute([$title, $url]);
if($query1){
header("Location: ". $_SERVER['HTTP_REFERER']);
}
}
<form action="" method="post">
<div class="form-group">
<small>MicroWallets Name</small>
<select class="form-select" aria-label="Default select example">
<option selected>MicroWallets</option>
<?php foreach ($type as $value) { ?>
<option value="<?=$value->id ?>"><?=$value->title ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<small>Category Name</small>
<select class="form-select" aria-label="Default select example">
<option selected>Category</option>
<?php foreach ($category as $value) { ?>
<option value="<?=$value->id ?>"><?=$value->title ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<small>Title</small>
<input type="text" class="form-control" name="title">
</div>
<div class="form-group">
<small>Url</small>
<input type="text" class="form-control" name="url">
</div>
<div class="form-group">
<small>Time</small>
<input type="text" class="form-control" name="time">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="add">Save</button>
</div>
</form>
Answer the question
In order to leave comments, you need to log in
<select class="form-select" name="select_1"
<select class="form-select" name="select_2"
$title = $_POST['name'];
$url = $_POST['url'];
$get_id_type = $_GET['id'];
$select_1 = $_POST['select_1'];
$select_2 = $_POST['select_2'];
$sql = ("INSERT INTO `xf_type` (`title`, `url`,`select_1`, `select_2`) VALUES (?,?,?,?)");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question