John Martin John Martin - 1 year ago 159
MySQL Question

I want to display data inserted into database after submission

I have a generator script, it basically generates random tokens and stores them in a MySQL database. Several people will use it and what I want to do it basically show the generated tokens that were just generated on the generation page so that when they generate tokens and they're all mixed up with others they can easily copy the ones they generated without having to go through the whole table of everyone's tokens.

I have put the entire form and script here, the submission part works perfect, just wondering about that extra feature and if it would be a possibility.

<?php
function randString($length, $charset='ABCEFGHJKLMNPRTUVWXY23456789' )
{
$str='' ;
$count=strlen($charset);
while ($length--) {
$str.=$charset[mt_rand(0, $count - 1) ];
}
return $str;
}

if (isset($_POST[ 'create'])) {
$token_semi_quantity=0 ;
$token_combo=$ _POST[ 'howmany'];
$seller=$_POST[ 'seller'];
while ($token_semi_quantity < $token_combo) {
$token=randString(4) . "-" . randString(4) . "-" . randString(4);
$token_semi_quantity++;
$token_info=$_POST[ 'tokeninfo'];
$token_explode=e xplode( ',', $token_info);
$token_time=$token_explode[0];
$token_desc=$token_explode[1];
$NowDateTime=date( "Y-m-d H:i:s");
// Log dat shit
$WhoGenDatToken=$userRow[ 'username'] . ' Generated Token <b>' . $token . '</b> at ' . date( "m-d-Y h:i") . ' CST.';
$gen_token=new CONNECT;
$insert_token=( "INSERT INTO `tokens`
(`id`, `token`, `time`, `generatedby`,
`timegenerated`, `used`, `seller`,
`description`)
VALUES ('NULL', :generatetokenVal,
:generatetokentimeVal, :generatetokenadminName,
:generateDateTime, '0',
:generatetokenSeller, :generatetokenDesc);
INSERT INTO `admin_act` (`activity`)
VALUES(:WhoGenDatTokenDen)");
$stmt=$gen_token->runQuery($insert_token);
$stmt->execute(Array( ':generatetokenVal' => $token,
':generatetokentimeVal' => $token_time,
':generatetokenadminName' => $adminName,
':generateDateTime' => $NowDateTime,
':generatetokenSeller' => $seller,
':generatetokenDesc' => $token_desc,
':WhoGenDatTokenDen' => $WhoGenDatToken ));

}
}
?>
<!-- PAGE CONTENT WRAPPER -->
<div class="page-content-wrap">
<div class="row">
<h2>&nbsp;&nbsp;<span class="fa fa-tags"></span>&nbsp;<?php
echo $xblsname; ?> Token Generator</h2>
<div class="col-md-12">
<div class="panel panel-default tabs">
<div class="panel-body tab-content">
<div class="tab-pane active" id="tab-first">
<div class="col-md-3">
<h3><?php
echo $xblsname; ?> Token Generator</h3>
<form method="POST" class="form-horizontal">
<div class="form-group">
<label class="col-md-3 col-xs-12 control-label">How Many?</label>
<div class="col-md-6 col-xs-12">
<select class="form-control select" name="howmany">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
<span class="help-block">Choose how many to generate</span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-12 control-label">Token Type</label>
<div class="col-md-6 col-xs-12">
<select class="form-control" name="tokeninfo" id="tokeninfo">
<option value="1,1 Day Server Time">1 Day Server Only</option>
<option value="3,3 Days Server Only">3 Days Server Only</option>
<option value="7,1 Week Server Only">1 Week Server Only</option>
<option value="14,2 Weeks Server Only">2 Weeks Server Only</option>
<option value="31,1 Month Server Only">1 Month Server Only</option>
<option value="110,1 Day with GTA Menu">1 Day with GTA Menu</option>
<option value="111,3 Days with GTA Menu">3 Days with GTA Menu</option>
<option value="112,1 Week with GTA Menu">1 Week with GTA Menu</option>
<option value="113,2 Weeks with GTA Menu">2 Weeks with GTA Menu</option>
<option value="114,1 Month with GTA Menu">1 Month with GTA Menu</option>
<option value="999,Custom Token 1">Custom Token 1</option>
</select>
<span class="help-block">Choose token value</span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-12 control-label">Seller</label>
<div class="col-md-6 col-xs-12">
<select class="form-control" name="seller">
<?php // Don 't change the options here - do it in includes/settings.php -JohnC
if (!empty($seller1)) print "<option value=\"" . $seller1 . "\">" . $seller1 . "</option>";
if (!empty($seller2)) print "<option value=\"" . $seller2 . "\">" . $seller2 . "</option>";
if (!empty($seller3)) print "<option value=\"" . $seller3 . "\">" . $seller3 . "</option>";
if (!empty($seller4)) print "<option value=\"" . $seller4 . "\">" . $seller4 . "</option>";
if (!empty($seller5)) print "<option value=\"" . $seller5 . "\">" . $seller5 . "</option>";
if (!empty($seller6)) print "<option value=\"" . $seller6 . "\">" . $seller6 . "</option>";
if (!empty($seller7)) print "<option value=\"" . $seller7 . "\">" . $seller7 . "</option>";
if (!empty($seller8)) print "<option value=\"" . $seller8 . "\">" . $seller8 . "</option>";
if (!empty($seller9)) print "<option value=\"" . $seller9 . "\">" . $seller9 . "</option>";
if (!empty($seller10)) print "<option value=\"" . $seller10 . "\">" . $seller10 . "</option>";
if (!empty($seller11)) print "<option value=\"" . $seller11 . "\">" . $seller11 . "</option>";
if (!empty($seller12)) print "<option value=\"" . $seller12 . "\">" . $seller12 . "</option>";
if (!empty($seller13)) print "<option value=\"" . $seller13 . "\">" . $seller13 . "</option>";
if (!empty($seller14)) print "<option value=\"" . $seller14 . "\">" . $seller14 . "</option>";
if (!empty($seller15)) print "<option value=\"" . $seller15 . "\">" . $seller15 . "</option>";
?>
</select>
<span class="help-block">Choose seller</span>
</div>
</div>
</div>
<div class="panel-footer">
<button name = "create" class="btn btn-primary pull-right">Generate Token(s) <span class="fa fa-magic fa-right"></span></button>
</form>
</div>




</div>
</div>
</div>
</div>
</div>
</div>


Thanks for any help in advanced.

Answer Source

Inside the while loop, store the token into an array/collection/list

// inside while loop, after $token = ...
$generatedtoken[] = $token;

then wherever you want to show/list them:

foreach($generatedtoken as $token) {
    echo $token; // some markup maybe added
}

appending to a var that's not considered an array (yet) is probably dirty, so before the if or somewhere appropriate, instantiate the array.

$generatedtoken = array();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download