Hello everyone, I need to transfer the data from the linked list to a table in the database. Here is the code for creating a select:
<script type="text/javascript" src="jquery-3.2.1.js"> </script> <script type="text/javascript"> $(document).ready(function(){ $(".country").change(function(){ var id = $(".country").val(); $.ajax({ type: "POST", url: "command.php", data: {id: id}, success: function(data) { $(".command").html(data); } }); }); }); </script> </head> <body> <select size='1' class="country"> <option value="0">--Your country--</option> <?php $query = $db->query("SELECT * FROM `country`"); while($row = $query->fetch()) { echo "<option value='{$row->id}'>".$row->title."</option>"; } ?> Here is the code with the creation of command.php:
<script> $(function(){ $('select[name="command"]').change(function() { alert($('select[name="command"]').val()); }); }); </script> <?php require_once 'connect_bd.php'; if(isset($_POST['id']) && !empty($_POST['id'])) { $id = intval($_POST['id']); $query = $db->query("SELECT * FROM `region` WHERE `id_contry` = $id"); echo "<select name='command'>"; while($row = $query->fetch()) { echo "<option>{$row->title}</option>"; } echo "</select>"; $country = strip_tags(trim($_POST['country'])); $region = strip_tags(trim($_POST['region'])); mysqli_query($link, " INSERT INTO users_list(country, region) VALUES ('$country','$region') "); echo $country"; } else { echo "<select name='command' disabled><option value='0'>--Your region--</option></select>"; } ?> Here is the data transfer code from the form:
if(isset($_POST['submit'])) { $name = strip_tags(trim($_POST['name'])); $email = strip_tags(trim($_POST['email'])); $number = strip_tags(trim($_POST['number'])); $country = strip_tags(trim($_POST['country'])); $region = strip_tags(trim($_POST['region'])); $time = $_POST['time']; mysqli_query($link, " INSERT INTO users_list(name, email, number, country, region, time) VALUES ('$name','$email','$number','$country','$region', '$time') "); } if(empty($_POST['name']) == TRUE) { if (empty($_POST["name"])) { $nameError = "Your name is not correct: <br>"; echo $nameError; } else { $name = test_input($_POST["name"]); } if (empty($_POST["email"])) { $emailError = "Your email is not correct:: <br>"; echo $emailError; } else { $email = test_input($_POST["email"]); } if (empty($_POST["number"])) { $numberError = "Your number is not correct: <br>"; echo $numberError; } else { $number = test_input($_POST["number"]); } } It is necessary for me that at form filling the data from were transferred to the separate table with the data. Please help me figure it out.