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.");
  
   }
    }
}
  • the first condition in you forgot to start "{" and last you added one extra ''}". – Full Stop Sep 23 '20 at 04:08
  • Does this answer your question? [How do I compare input to mysql data with php/sql?](https://stackoverflow.com/questions/16619164/how-do-i-compare-input-to-mysql-data-with-php-sql) – AmirAli Esteki Sep 23 '20 at 04:11
  • **WARNING**: Writing an access control layer is not easy and there are many opportunities to get it severely wrong. Any modern [development framework](https://www.cloudways.com/blog/best-php-frameworks/) like [Laravel](http://laravel.com/) comes with an [authentication system](https://laravel.com/docs/master/authentication) built-in, and there are [authentication libraries](http://phprbac.net/) you can use. At the absolute least follow [recommended security best practices](http://www.phptherightway.com/#security) and **never store passwords as plain-text** or a weak hash like **SHA1 or MD5**. – tadman Sep 23 '20 at 04:21
  • Why are you selecting every row, and then calling, inexplicably, some other code that seems completely different? – tadman Sep 23 '20 at 04:22

1 Answers1

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.");
}
Data Do IT
  • 11
  • 4
  • 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. – Ubong Ekere Sep 23 '20 at 20:31