select不能将值插入db

时间:2017-03-31 09:08:24

标签: php mysql

我遇到了问题。我似乎无法将所选值插入db。

这只是一个例子...... 当我点击提交按钮时,它只会刷新。

<form method="POST">
<?php
        $sql = "SELECT username FROM tbl_users";
        $result = mysqli_query($con,$sql);
        ?>
       <select type='text' class='form-control' name='username'>
       <?php
       echo "<option value=0>" .'User'."</option>";
       while ($row = mysqli_fetch_array($result)) {
       echo "<option value='" . $row['username'] ."'>" . $row['username'] ."</option>";
       }
       ?>
       </select><br>



<button name="save" class="btn btn-primary btn-block" type="submit" id="save" title="Click to Save"><i class="fa fa-check"> Save</i></button>


</form>

<?php
if (isset($_POST['save'])){
$username = $_POST['username'];
$sql= "INSERT INTO tbl_out (username) values('$username')"; //it should be inserted to the other table.
$res = $con->query($sql);
header("Location: users_out.php");
?>
<?php
}
?>

0 个答案:

没有答案