Beginner Needing MySQL help-$15 tip to paypal account - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

Tecnotic
Posts: 1
Joined: Mon May 07, 2012 8:30 pm

Beginner Needing MySQL help-$15 tip to paypal account

I am using this pre-generated code to have my serial numbers validate on my MySQL database:

Code: Select all

<?php

// server response codes
define('LICENSE_VALID',   '601');
define('LICENSE_INVALID', '602');

// database connection parameters
$db_host = HIDDEN;
$db_user = HIDDEN;
$db_pass = HIDDEN;
$db_name = HIDDEN;

// client information table
$clients_tbl_name = 'clients';
$sn_tbl_col       = 'serial_no';
$lic_no_tbl_col   = 'license_no';
$val_no_tbl_col   = 'validations_no';

// serial validation results
$serial_invalid = 0;    // invalid serial
$serial_ok      = 1;    // valid serial
$val_exceeded   = 2;    // valid serial but maximum number of validations exceeded

/**
 * Server HTTP response to the query issued by Advanced Installer serial validation tool.
 * 
 * @param $valResult represents the result of the serial validation and has one of the 
 *                   above values: $serial_invalid, $serial_ok, $act_exceeded 
 */
function ServerResponse($valResult, $posted_serial = '', $lang_id = 1033)
{
  global $serial_invalid, $serial_ok, $val_exceeded;
  
  $msg_sep = "\n";
  
  // load error messages from your database, using "$lang_id" for localization (optional)
  
  if($posted_serial == '')
    return LICENSE_INVALID . $msg_sep . "Missing Serial Number !";
  
  switch($valResult)
  {
    case $val_exceeded:
      return LICENSE_INVALID . $msg_sep . 'Maximum number of validations exceeded for Serial Number: ' . $posted_serial;
    case $serial_ok:
      return LICENSE_VALID;
    default:
      return LICENSE_INVALID . $msg_sep . 'Serial Number: ' . $posted_serial . ' is invalid !';
  }
}

// Variables POSTed by Advanced Installer serial validation tool to this web page: "sn", "languageid".
if(isset($_POST['sn']) && trim($_POST['sn']) != '')
{
  // get the serial number entered by the installing user in the "UserRegistrationDlg" dialog 
  $sn = trim($_POST['sn']);
  
  // get the system language ID of the user's machine
  // (you can use this parameter to display a localized error message taken from your database)
  $languageid = (int) $_POST['languageid'];
  
  // connect to database
  $db_conn = @mysql_connect($db_host, $db_user, $db_pass);
  if(!$db_conn)
  {
    // issue error response
    echo ServerResponse($serial_invalid, $sn, $languageid);
    die();
  }
  
  // select target database
  $db_selected = @mysql_select_db($db_name, $db_conn);
  if(!$db_selected)
  {
    // issue error response
    echo ServerResponse($serial_invalid, $sn, $languageid);
    die();
  }
  
  // prepare SQL statement
  $sn_query = sprintf("SELECT `%s`, `%s`, `%s` FROM `%s` WHERE `%s` = '%s'", 
    $sn_tbl_col, $lic_no_tbl_col, $val_no_tbl_col, 
    $clients_tbl_name, $sn_tbl_col, mysql_real_escape_string($sn));
  
  // execute query
  $result = @mysql_query($sn_query, $db_conn);
  
  // get result set size
  if(@mysql_num_rows($result) == 0)
  {
    // serial number NOT found in database => issue error response
    echo ServerResponse($serial_invalid, $sn, $languageid);
    die();
  }
  else // serial number was found in database
  {
    // fetch the result row as an associative array 
    $row = @mysql_fetch_array($result, MYSQL_ASSOC);
    if(!$row)
    {
      // issue error response
      echo ServerResponse($serial_invalid, $sn, $languageid);
      die();
    }
    
    // increment the validations_no column
    $inc_val_no_query = sprintf("UPDATE `%s` SET `%s` = `%s` + 1 WHERE `%s` = '%s'",
      $clients_tbl_name, $val_no_tbl_col, $val_no_tbl_col, 
      $sn_tbl_col, mysql_real_escape_string($sn));
    
    // execute the update query
    @mysql_query($inc_val_no_query, $db_conn);

    // check whether the user has reached maximum number of validations
    $license_no    = (int) $row[ $lic_no_tbl_col ];
    $validation_no = (int) $row[ $val_no_tbl_col ];
    
    if($validation_no >= $license_no)
    {
      // issue error response => maximum number of validations exceeded
      echo ServerResponse($val_exceeded, $sn, $languageid);
      die();
    }
    else
    {
     // issue SUCCESS response
     echo ServerResponse($serial_ok, $sn, $languageid);
     die();
    }
  }
}
else
{
  // issue error response
  echo ServerResponse($serial_invalid);
  die();
}

?>
It works great, but at this page-- Image
I need the name, email, phone number to be sent into the mysql database so I can keep track of my customers. the Serial number field does what its supposed to do. I will tip whomever whatever amount if I can get this to work. If you want to remote in and do it, that's fine.

**THIS IS WHAT THE DATABASE LOOKS LIKE** I just need it to be filled into the other blank fields.
Image
CiprianComsa
Posts: 110
Joined: Thu Aug 19, 2010 10:11 am
Contact: Website

Re: Beginner Needing MySQL help-$15 tip to paypal account

Hi,

if you want to collect the user name's, the company's name, the user's email, and his language, you set the property HttpPostCollectData with the value: USERNAME;COMPANYNAME;USER_EMAIL;UserLanguageID.
You can find more information on the next article "How do I collect installation data and send it to my web server?".

Regards,
Ciprian
__________________________________________________________________________________________________________________________________________________
Ciprian Comsa
Advanced Installer Team
http://www.advancedinstaller.com/
Ciprian Comsa - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”