there is a table "prosto", there are fields "b", "cart", "data" in it, data from the form should be sent to the table from the form, if the date is added, the error Undefined index appears for the other fields: b, cart. The fields "b" and "cart" are made as select and are taken from the tables "buro" and "cartr", respectively.
main.php:
<html> <body> <h4>Добавить картридж</h4> <form> <div class="form-group"> <label for="select1">№ бюро</label> <?php $sql2 = "SELECT `b` FROM `buro`"; $result2 = $conn->query($sql2); echo '<select class="form-control" name="b" value="b">'; while ($myrow1 = mysqli_fetch_array ($result2)) { echo '<option value="'.$myrow1['b'].'">'.$myrow1['b'].'</option>'; } echo "</select >"; ?> </div> <div class="form-group"> <label for="select2">Картридж</label> <?php $sql0 = "SELECT `cart` FROM `cartr`"; $result1 = $conn->query($sql0); echo '<select id="cart" class="form-control" name="cart" value="cart">'; while ($myrow = mysqli_fetch_array ($result1)) { echo '<option value="'.$myrow['cart'].'">'.$myrow['cart'].'</option>'; } echo '</select>'; ?> </div> <div class="form-group"> <label for="data">Дата</label> <input type='text' class="form-control" id='datetimepicker2' name="data" required /> </div> <script type="text/javascript"> $(function () { $('#datetimepicker2').datetimepicker({ locale: 'ru', //format: 'YYYY-MM-DD' }); }); </script> </form> <a href=dob.php><input name="dob" type="button" class="btn btn-warning" value="Сохранить"></a> </div> </body> </html> dob.php:
<?php $hostname = 'localhost'; $username = 'root'; $passwordname = ''; $basename = 'test'; $conn = new mysqli($hostname, $username, $passwordname, $basename) or die ('Невозможно открыть базу'); $b=$_POST['b']; $cart=$_POST['cart']; //$data = date("Ymd"); $sql1= "INSERT INTO `prosto` SET `data`=NOW()"; $sql2= "INSERT INTO `prosto` VALUES ('$b','$cart')"; $res1=$conn->query($sql1); $res2=$conn->query($sql2); ?> 