Note that there are some explanatory texts on larger screens.

plurals
  1. POKey Generator without storing in database
    primarykey
    data
    text
    <p>My code creates random <code>key</code> and stores it in the <code>database</code>on button click,<code>keygen</code> is the button name, <code>if</code> the user/customer already has the key it gets the <code>key</code> from the database in a text box on click <code>else</code> it generates a new <code>key</code> and stores it in the <code>database</code> . Is there a way i can achieve this without storing the <code>key</code> in the database and get the same key for a particular user/customer each time. </p> <p>Code:</p> <pre><code>&lt;?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 &lt; $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } return $randomString; } ?&gt; </code></pre> <p>My HTML is,</p> <pre><code>&lt;div id="content" class="box2"&gt; &lt;div class="login"&gt; &lt;form action="" method="post" style="margin:12px;"&gt; &lt;table class="nostyle"&gt; &lt;tr&gt; &lt;td align="center"&gt; &lt;label style="font-size:16px;"&gt;&lt;strong&gt;Customer ID: &lt;/strong&gt;&lt;/label&gt; &lt;select name="customer_no"&gt; &lt;?php $result_customer= mysql_query('SELECT customer_no FROM customer ORDER BY customer_no'); ?&gt; &lt;?php while($row_customer= mysql_fetch_assoc($result_customer)) { ?&gt; &lt;option &lt;?php if ($row_customer['customer_no']=='') { ?&gt; selected="selected"&lt;?php } ?&gt;&gt; &lt;?php echo htmlspecialchars($row_customer['customer_no']); ?&gt; &lt;/option&gt; &lt;?php } ?&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="center"&gt;&lt;label style="font-size:16px;"&gt;&lt;br /&gt;&lt;strong&gt;Register Key: &lt;/strong&gt; &lt;/label&gt; &lt;input type="text" id="key" class="input-text" name="key" size="20" align="middle" value = " &lt;?=$row["key"];?&gt;"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;td align="center"&gt;&lt;br /&gt;&lt;input type="submit" id="keygen" class="input-submit" name="keygen" value="Generate" onclick=""/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Please help,I'm a newbie.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload