bradg
Posts: 3
Joined: Tue Mar 03, 2020 11:56 am

sendCollectedData data formatting

Hi all
I am using SendCollectedData to send the following properties to my webserver

Username
Companyname
User_email
PIDKEY

When I check my database on the server All is working as expected with correct values inserted into the fields, apart from PIDKEY (MaskedEdit serial code edit box).

The serial code entered in this example was:
08595-12348-81035-08964-55974

but yet the field in the database contains -149726

Is this a datatype issue or something? I have all database fields as VarChars

Any help would be greatly appreciated :)

Code: Select all

// get the user's serial
$serial = $_POST['PIDKEY'];

// connect to database
$db_conn = @mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if(!$db_conn)
{
  // issue error response
  die();
}

// prepare SQL statement
$sn_query = "INSERT INTO `registration` (`user_name`, `company`, `email`, `serial`) VALUES ('" . 
             mysqli_real_escape_string($db_conn, $username) . "', '" . mysqli_real_escape_string($db_conn, $company) . "', '" . 
             mysqli_real_escape_string($db_conn, $email) . "', " . mysqli_real_escape_string($db_conn, $serial) . ");";
             
             
             
             
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: sendCollectedData data formatting

Hello and welcome to Advanced Installer forums,

Most probably, this indeed looks like a datatype issue.

However, to be sure of this, please try to manually create the table and insert the elements into it as in your script. If the error persists, then this most likely is a datatype issue.

One thing I am thinking about is maybe the fact that you have surpassed the limit of your declarations. For instance, if you declared the PIDKEY as VARCHAR(10) and the PIDKEY actually contains more characters, then it might be failing.

Hope this helps somehow.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
bradg
Posts: 3
Joined: Tue Mar 03, 2020 11:56 am

Re: sendCollectedData data formatting

Hi Catalin
Thankyou for taking the time to reply.

I tried this by copying the 'insert into' statement into phpMyAdmin, and it has worked as expected, displaying the data correctly. At least it rules out a configuration issue with the table.

Can you think of any settings within AdvancedInstaller which could affect this, or do I need to declare the variable $serial as a different type within the collect_db.php?

Code: Select all

// get the user name used for registration
$username = trim($_POST['USERNAME']);

// get the company name used for registration
$company = trim($_POST['COMPANYNAME']);

// get the email address used for registration
$email = trim($_POST['USER_EMAIL']);

// get the user's serial
$serial = $_POST['PIDKEY'];


bradg
Posts: 3
Joined: Tue Mar 03, 2020 11:56 am

Re: sendCollectedData data formatting

Hi
I have fixed this, though I thought I'd share it here incase anyone else is looking for it.

I originally changed the last part of the below code from getting an integer value to a string. I did not add single quotations surrounding it.

Below is the original code, with the addition of the two quotations which I have made red


$sn_query = "INSERT INTO `registration` (`user_name`, `company`, `email`, `serial`) VALUES ('" .
mysqli_real_escape_string($db_conn, $username) . "', '" . mysqli_real_escape_string($db_conn, $company) . "', '" .
mysqli_real_escape_string($db_conn, $email) . "',' " . mysqli_real_escape_string($db_conn, $serial) . " ' );";
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: sendCollectedData data formatting

Hello,

Thank you for your followup on this and for sharing your solution with us.

I am really glad you got this working.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”