简体   繁体   中英

How to compare a php input field and mysql database table

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.");
  
   }
    }
}

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.");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM