PHP-单击“提交”时,文本框中显示的随机数据

时间:2018-12-13 11:14:58

标签: php html mysql forms

你好,我有一个数据库,它的数据是这个,请看这张图片

here is my image

我需要解决此问题的方法,解决方案是我需要更改数据而不是重复数据,因此当我输入写在数据库中的值时,文本框上显示的值不会每次都重复并更改输入相同的值。

<form action="" method="POST">
    <div class="row  col-md-4">
        <label>Amount</label>
        <input type="text" name="id" class="form-control validate"> 
        <br>
        <input type="submit" class="form-control btn-warning" name="search" value="Search Data"></input><br>
        //HERE IS WHERE I SUBMIT THE DATA RIGHT NOW IT IS NOT RANDOMIZED WHEN I SUBMIT AGAIN THE SAME VALUE APPEARS

<?php 
    $connection = mysqli_connect("localhost","root","");
    $db = mysqli_select_db($connection, 'qrproject');

    if(isset($_POST['search'])){
    $id = $_POST['id'];

    $query = "SELECT * FROM scratch_cards WHERE amount='$id' ";
    $query_run = mysqli_query($connection, $query);

    while($row = mysqli_fetch_array($query_run)) {
?>
        <form action="" method="POST">
            <input type="text" name="code" value="<?php echo $row['code'] ?>" class="form-control validate" id="mapo">
            <input type="text" name="pin" value="<?php echo $row['pin'] ?>" class="form-control validate" id="mact">
            <input type="text" name="status" value="<?php echo $row['status'] ?>" class="validate form-control" id="soluong">
            <input type="date" name="card_expiration" value="<?php echo $row['card_expiration'] ?>" class="validate form-control" id="cardex">
            <input type="number" name="card_validity" value="<?php echo $row['card_validity'] ?>" class="validate form-control" id="cardval">
        </form>
<?php 
    }
}
?>   
</form>

1 个答案:

答案 0 :(得分:-1)

也许根据您的评论,您需要唯一的记录,因此您可以在查询中使用DISTINCT,因此通过将DISTINCT赋予任何列,您将不会得到重复的记录。

在您的情况下:

SELECT DISTINCT id, amount FROM scratch_cards WHERE amount='$id'

也许这可以帮助您获取唯一记录