0

. key_ database_ keygen_ if_ key_ else_ key_ database_ データベースに保存せずにこれを達成keyし、特定のユーザー/顧客に対して毎回同じキーを取得する方法はありますか?

コード:

<?php
include('session.php');
$result = mysql_query("SELECT * FROM customer WHERE customer_no = '$customer_no'");
$row = mysql_fetch_array($result);
if (isset($_POST['keygen'])){
$customer_no = $_POST['customer_no'];
$customer_no = mysql_real_escape_string($customer_no);
$result = mysql_query("SELECT * FROM customer WHERE customer_no = '$customer_no'");
while ($row = mysql_fetch_assoc($result)) {
$keyString = $row['key'];
if($keyString == ""){
$keyString = mysql_real_escape_string($keyString);
$query = mysql_query("UPDATE customer SET `key` = '$keyString' WHERE customer_no = '$customer_no'");
}
else{
$keyString = $row['key'];
}}} 

function  generateRandomString($length = 10) {  
$characters = '23456789ABCDEFGHJKMNPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
    $randomString .= $characters[rand(0, strlen($characters) - 1)];
} 
return $randomString;
}

?>

私のHTMLは、

<div id="content" class="box2">
<div class="login">
<form action="" method="post" style="margin:12px;">
<table class="nostyle">
<tr>
<td align="center">
<label style="font-size:16px;"><strong>Customer ID: </strong></label>
<select name="customer_no">
<?php $result_customer= mysql_query('SELECT customer_no FROM customer ORDER BY   customer_no'); ?>
<?php while($row_customer= mysql_fetch_assoc($result_customer)) { ?>
<option <?php if ($row_customer['customer_no']=='') { ?> selected="selected"<?php } ?>> <?php echo htmlspecialchars($row_customer['customer_no']); ?> </option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td align="center"><label style="font-size:16px;"><br /><strong>Register Key: </strong> </label>
<input type="text" id="key" class="input-text" name="key" size="20" align="middle"   value = " <?=$row["key"];?>"></td>
 </tr>
 <td align="center"><br /><input type="submit" id="keygen" class="input-submit" name="keygen" value="Generate" onclick=""/>
 </td>
 </tr>
 </table>
 </form>
 </div>
 </div>

助けてください、私は初心者です。

4

2 に答える 2