Note that there are some explanatory texts on larger screens.

plurals
  1. PORegistration key generator
    primarykey
    data
    text
    <p>I am trying to create a program that creates random registration keys and stores it in the database.If the user/customer already has a registration code it displays that key stored in the database in a text box on click 'else' it generates a new key and stores it in the database.The problem is i am not being able to store the key in the database.My code is:</p> <pre><code>&lt;?php if (isset($_POST['keygen'])){ $customer_no = $_POST['customer_no']; $result = mysql_query("SELECT * FROM customer WHERE customer_no = '$customer_no'"); $row = mysql_fetch_array($result); $keyString = $row['key']; if($keyString == ""){ $keyString = generateRandomString(); $query = "UPDATE 'customer' SET key ='$keyString' WHERE customer_no = '$customer_no'"; mysql_query($query); echo $keyString; } else{ echo $keyString; } } function generateRandomString($length = 8) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randomString = ''; for ($i = 0; $i &lt; $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } return $randomString; } ?&gt; </code></pre> <p>this is my HTML:</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>I am a newbie, and am not that sure about the code.Please help!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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