0

我正在设计一个产品注册系统,它接受已经保​​存在数据库中的 XXXXX-XXXXX-XXXXX-XXXXX 作为密钥。我想检查密钥是否在数据库中注册,如果是,则必须输入其他字段,如姓名、电子邮件 ID、联系电话等。但我不知道如何验证用户提交的产品密钥,因为注册表包含以下代码:

 <tr>
    <td><span>Product Key:</span></td>
    <td>
        <input type="text" id="productkey" onKeyUp="moveOnMax(this,productkey2)" size="4" maxlength="5" /> 
         - <input type="text" id="productkey2" onKeyUp="moveOnMax(this,productkey3)" size="4" maxlength="5" /> 
         - <input type="text" id="productkey3" onKeyUp="moveOnMax(this,productkey4)" size="4" maxlength="5"/> 
         - <input type="text" id="productkey4" size="4" maxlength="5"/>
    </td>
  </tr>

除了产品密钥,我知道如何将其余信息保存在数据库中。

4

2 回答 2

0

我的php知识薄弱,但我希望这会对你有所帮助

<?php
////// Post Data from HTML Form
$serialNumber = $_POST['prodectkey'];

////// Your Database Connection Informaiton
$DB_HostName = "127.0.0.1";
$DB_Name = "products";
$DB_User = "root";
$DB_Pass = "root";
$DB_Table = "serial";


////// Connection Happen Here
$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error()); 
mysql_select_db($DB_Name,$con) or die(mysql_error()); 

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$result1 = mysql_query("SELECT * FROM prodects where key=$serialNumber");
$column = array();

while($row = mysql_fetch_array($result))
{

    $column[] = $row['key'];
   $conted = count($column);

}
if ($conted == 1) {
  echo "Done I could find it in the database";
}else{
echo "I couldn't find it :(";
}

mysql_close($con);

?>
于 2013-03-15T06:31:31.537 回答
0
 <input type="text" id="productkey" name="first" onKeyUp="moveOnMax(this,productkey2)" size="4" maxlength="5" /> 
- <input type="text" name="second" id="productkey2" onKeyUp="moveOnMax(this,productkey3)" size="4" maxlength="5" /> 
- <input type="text" name="third" id="productkey3" onKeyUp="moveOnMax(this,productkey4)" size="4" maxlength="5"/> 
- <input type="text" name="fourth" id="productkey4" size="4" maxlength="5"/>

您需要name文本框的属性,因为 PHP 使用它来识别输入数据。然后你可以简单地做

$userEnteredProductKey = $_POST['first'].'-'.$_POST['second'].'-'.$_POST['third'].'-'.$_POST['fourth'];
// $userEnteredProductKey will contain data in xxxxx-xxxxx-xxxxx-xxxx format

然后$userEnteredProductKeyWHERE您的 SQL 查询的子句中使用来比较数据。

于 2013-03-15T06:38:50.647 回答