0

Please I have two tables (keygen and sub2) in a database nassk. I created a form with the table sub2 keygen fields are keygenID, Keygen while sub2 fields are SubID, Keygen, userID, Date_Sub

i was to correct my code on my form Sub2 with fields like $ID, $KeyGen, $userID, to be able to to check the database and if the form field $Keygey is == to the table keygen field Keygen, then the form should submit else it should raise error.

below are code i have use

global $subscription;
$db = new clsDBConnection1();
    $SQL = "SELECT KeyGen FROM keygen";
    $Result = mysqli_query($SQL);
   if(mysqli_num_rows($Result) > 0) 
   
  if (($Result) !== $subscription->KeyGen->GetValue())
    
  {
     $subscription->Errors->addError("The values of Password and Confirm fields do not match.");
  
   }
    }
}
4
  • the first condition in you forgot to start "{" and last you added one extra ''}". Commented Sep 23, 2020 at 4:08
  • Does this answer your question? How do I compare input to mysql data with php/sql? Commented Sep 23, 2020 at 4:11
  • WARNING: Writing an access control layer is not easy and there are many opportunities to get it severely wrong. Any modern development framework like Laravel comes with an authentication system built-in, and there are authentication libraries you can use. At the absolute least follow recommended security best practices and never store passwords as plain-text or a weak hash like SHA1 or MD5. Commented Sep 23, 2020 at 4:21
  • Why are you selecting every row, and then calling, inexplicably, some other code that seems completely different? Commented Sep 23, 2020 at 4:22

1 Answer 1

0

You're way off, but let's get you going in the right direction. To save yourself (and others) headaches in the future, try not to name your tables and fields similarly - give it more creativity. Don't let a table field also have the same name as the table itself. Also avoid capitalization; use only lowercase. That becomes a big deal later should your application move from database to database and/or platform to platform.

In your form's On Validate event:

global DBConnection1;
$db = new clsDBConnection1();
$KeyGen_posted = $Component->KeyGen->GetValue();
$Result = CCDLookUp("*", "keygen", "KeyGen=" . CCToSQL($KeyGen_posted, ccsText), $db);
$db->close();
if (!$Result)
    $Container->Errors->addError("The values of Password and Confirm fields do not match.");
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much. I really made my day. I only made change to global $components. But the issue now is that i want the form input field to be Case Sensitive. That is exact value in the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.