function Puff_Member_Key_Create($Connection, $Username, $Key, $Value) { $Username = Puff_Member_Sanitize_Username($Username); $Key = htmlentities($Key, ENT_QUOTES, 'UTF-8'); $OldValue = Puff_Member_Key_Value($Connection, $Username, $Key); if ($OldValue) { return array('error' => 'Sorry, that UserKeyValue combination already exists.'); } $Result = mysqli_query($Connection, 'INSERT INTO `KeyValues`(`Username`, `Key`, `Value`) VALUES (\'' . $Username . '\', \'' . $Key . '\', \'' . $Value . '\');'); return $Result; }
function Puff_Member_Key_Destroy($Connection, $Username, $Key) { $Username = Puff_Member_Sanitize_Username($Username); $Key = htmlentities($Key, ENT_QUOTES, 'UTF-8'); $OldValue = Puff_Member_Key_Value($Connection, $Username, $Key); if (!$OldValue) { return array('error' => 'Sorry, that UserKeyValue combination doesn\'t exist.'); } //// Destroy the User $Result = mysqli_query($Connection, 'DELETE FROM `KeyValues` WHERE `Username`=\'' . $Username . '\' AND `Key`=\'' . $Key . '\';'); return $Result; }
$Key = 'FavColor'; $Value = 'Blue'; echo 'Puff_Member_Key_Create' . PHP_EOL; $Result['Create'] = Puff_Member_Key_Create($Connection, $Username, $Key, $Value); var_dump($Result['Create']); // true echo 'Puff_Member_Key_Value' . PHP_EOL; $Result['Value'] = Puff_Member_Key_Value($Connection, $Username, $Key); var_dump($Result['Value']); // string echo 'Puff_Member_Key_Update' . PHP_EOL; $Value = 'Red'; $Result['Update'] = Puff_Member_Key_Update($Connection, $Username, $Key, $Value); var_dump($Result['Update']); // true echo 'Puff_Member_Key_Like' . PHP_EOL; $Result['Like'] = Puff_Member_Key_Like($Connection, $Username, $Key); var_dump($Result['Like']); // mysqli_object echo 'Puff_Member_Key_Destroy' . PHP_EOL; $Result['Destroy'] = Puff_Member_Key_Destroy($Connection, $Username, $Key); var_dump($Result['Destroy']); // true echo 'Puff_Member_Key_Value' . PHP_EOL; $Result['Value2'] = Puff_Member_Key_Value($Connection, $Username, $Key); var_dump($Result['Value2']); // NULL $Result['Value2'] = !$Result['Value2']; if (in_array(false, $Result, true)) { exit(1); }