Im trying to make a generator where you will get something when you press a button. There are different types of generators and they are stores in sql. So i retrieve all the generators, and when i try to generate a random account from the db, it outputs the account for every generator type. I want it to only output the account on one specific generator type
$generators = mysqli_query($conn, "SELECT * FROM generators ORDER BY id ASC");
while($generator = mysqli_fetch_array($generators)) { ?>
<?php
$generatorname = $generator['name'];
if($_POST['generate']) {
$newaccount = mysqli_query($conn, "SELECT * FROM accounts WHERE module='$generatorname' order by RAND() LIMIT 1");
while($newacc = mysqli_fetch_array($newaccount)) {
$theaccount = $newacc['combo'];
}
}
$countstock = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM accounts WHERE module='$generatorname'"));
if(empty($theaccount)) {
$theaccount = "username:password";
}
?>
<div class="generator-box">
<div class="generator-stock"><?php echo $countstock; ?> in stock</div>
<div class="generator-title"><?php echo $generator['name']; ?></div>
<form method="post" src="">
<input type="text" class="generator-input" value="<?php echo $theaccount; ?>" readonly>
<input type="submit" class="generator-button" value="Generate" name="generate">
</form>
</div>