MySQL Forums
Forum List  »  PHP

MIstake in the code?
Posted by: Stavros Kokkineas
Date: January 16, 2018 07:46AM

<?php


// VARIABLES INTITIALIZATION

// Server and database connection information
$dbServer = "sql103.epizy.com";
$dbUsername = "epiz_21386760";
$dbPassword = "123456789";
$dbSchema = "epiz_21386760_emsrevolution";


// Username, Password and Device ID for logging in the database
$licenseNumber = $REQUEST ["licenseNumber"];
$userID = 0;
$deviceID = $_REQUEST ["deviceID"];
if ($deviceID == 0)
$deviceID = -1;


// Madrid time for updating and checking the IsLiveLastUpdated column
date_default_timezone_set('Europe/Madrid');
$date = date('Y/m/d H:i:s', time());

// We use positive * (with a + sign in front) * or negative * (with a - sign in front) * STRING codes to separate a successful registration procedure from an unsuccessful registration attempt
$exitCode = '-3';



// HELPER VARIABLES

// Successful registration response message
$successfulRegistrationMessage = "Device registered successfully.";

// Contact support generic resposne message
$contactSupportMessage = "...";










//////////////////////////////////////////////////////////////////// MYSQL QUERIES/ //////////////////////////////////////////////////////////////////////////////////////////

// LICENSE NUMBER CHECK
// Check ProvidersAccounts table to determine that the user trying to connect has a valid License Number
$con = new mysqli ($dbServer, $dbUsername, $dbPassword, $dbSchema);
$sql = "SELECT * FROM ProvidersAccounts WHERE `LicenseNumber` = '" .$licenseNumber."' ";

// LICENSE NUMBER QUERY
$licenseValid = mysqli_query($con, $sql);


// If the License Number exists in the ProvidersAccounts table check if the RequestForNewDeviceID flag is set to 1
// so we are certain that the user trying to register the current device is authorized to do so
if ( mysqli_num_rows ($licenseValid) == 1 ) {

$sql = "SELECT * FROM `ProvidersAccounts` WHERE `LicenseNumber` = '" .$licenseNumber."' AND `RequestForNewDeviceID` = 1";

// RequestForNewDeviceID is valid query
$requestForNewDeviceIDValid = mysqli_query($con, $sql);

if ( mysqli_num_rows ($requestForNewDeviceIDValid) == 1 ) {


$sql = "UPDATE `ProvidersAccounts` SET `DeviceID` = '" .$deviceID. "' , `RequestForNewDeviceID` = 0, `IsLive` = 1, `IsLiveLastUpdated` = '" .$date. "' WHERE `LicenseNumber` = '" .$licenseNumber. "' ";


// If we successfully updated the ProvidersAccounts table the registration was completed successfully so we return an appropriate success message
if ( mysqli_query ($con, $sql) ) {

$exitCode = "+1"
echo ( $exitCode );
echo ( $successfulRegistrationMessage );
}

// If there was a problem while trying to update the ProvidersAccounts table return an appropriate error message
else {

$exitCode = "-3"
echo ( $exitCode );
die ("There was a problem while trying to complete the registration procedure." . $contactSupportMessage);
} // END ELSE THERE WAS A PROBLEM WHILE TRYING TO UPDATE THE ProvidersAccounts TABLE

} // END IF REQUEST FOR NEW DEVICE ID WITH THE GIVEN LICENSE NUMBER IS VALID

// If the requestForNewDeviceID flag is not set to 1 for the given License Number - meaning the License Number given has already been used - return an appropriate error message
else {

$exitCode = '-5';
echo ($exitCode);
die ("The License Number given is already in use" . $contactSupportMessage);
} // END ELSE LICENSE NUMBER HAS ALREADY BEEN USED

} // END IF LICENSE NUMBER GIVEN IS VALID

// If the license number the user entered does not exists in our database return an appropriate error message
else {

$exitCode = '-6';
echo ($exitCode);
die ("License Number incorrect." .$contactSupportMessage);
}
?>


Can anyone please tell me what is wrong with the code above and of there is any way to debug php code easily?

Options: ReplyQuote


Subject
Written By
Posted
MIstake in the code?
January 16, 2018 07:46AM
January 16, 2018 02:10PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.