Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6806005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:39:26+00:00 2026-05-26T19:39:26+00:00

I have some troubles to find the right loop to check if some values

  • 0

I have some troubles to find the right loop to check if some values are contained in mysql DB.

I’m making a software and i want add license ID. Each User has x keys to use.

Now when the user start the client , it invokes a php page that check if the Key sent in the POST method is stored in DB or not.

If that key isnt store than i need to check the number of his keys. If it’s > than X i’ll ban him otherwise i add the new keys in the DB.

I’m new with PHP and MYSQL. I wrote this code and i would know if i can improve it.

<!-- language: php -->


                ....
                $user = POST METHOD 
                $licenseID = POST METHOD
                ....
                ....
                $resultLic= mysql_query("SELECT  id , idUser , idLicense FROM license WHERE idUser = '$user'") or die(mysql_error());
                $resultNumber = mysql_num_rows($resultLic);
                $keyFound = '0'; // If keyfound is 1 the key is stored in DB
                    while ($rows = mysql_fetch_array($resultLic,MYSQL_BOTH)) {
                           //this loop check if the $licenseID is stored in DB or not
                            for($i=0; $i< $resultNumber ; i++)
                                               { 
                                         if($rows['idLicense'] === $licenseID) {
                                         //Just for the debug 
                                              echo("License Found");
                                              $keyFound = '1';
                                               break;
                                               }
                  //If key isn't in DB and there are less than 3 keys the new key will be store in DB
                                     if($keyfound == '0' && $resultNumber < 3){
                                         mysql_query(Update users set ...Store $licenseID in Table) }
          // Else mean that the user want user another generated key (from the client) in the DB and i will be ban 
(It's wrote in TOS terms that they cant use the software on more than 3 different station)                    
                 else    {   mysql_query(update users set ban ='1'.....etc)
                                  }                               
                    }

I know that this code seems really bad so i would know how i can improve it. Someone Could give me any advice?

Update: I forgot to say that i choose to have 2 tables one users where is content all information about the users id , username , password etc and another table license where i get id , idUsername , idLicense (the last one store license that the software generate)

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:39:27+00:00Added an answer on May 26, 2026 at 7:39 pm

    I might be wrong, but why not issuing the search for the LicencsId to Mysql with this SQL query

    "SELECT id , idUser , idLicense FROM license WHERE idUser = '$user' AND idLicense='$licenseID'


    for security reasons escape the input
    "SELECT id , idUser , idLicense FROM license WHERE idUser = " . mysql_real_escape_string($user) . " AND idLicense=" . mysql_real_escape_string($licenseID)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble with an SQL statement that have to find the number
I have some troubles with positioning my label/password field. With this code they both
I have just installed Delphi 2010 and got some troubles with idHTTP component. If
Good Morning, i have some Trouble with the Zend Framework and Zend_DB_Select, i want
Greetings! I have some troubles enabling OAuth authentication for my web application running on
I have some troubles with JasperReports. I generated a formular with iReport including two
I'm making an App for iPad. But I faced some troubles because of Touch
I have a strange bug with Grails. I want to get back some persisted
I have some trouble with my trac installation (version 11.4). What should I do
I have some trouble with jquery ui-events: In my application, there are some sliders.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.