I want to check if there's a row with a specific value in a specific column.
I will check many columns, so I decided to create a function, for everything instead of creating a function specific
for each thing.
public function checkInfo($column, $parm)
{
$this->check = $this->pdo->prepare("SELECT * FROM recoveries WHERE :column = :parm");
$this->check->execute(array( ":column" => $column, ":parm" => $parm ));
if ($this->check->rowCount())
{
return true;
}
else
{
throw new exception ("Could not find recovery ".$parm.", ".$column."");
}
}
Variable column: The column name.
Variable parm: The parm name (Whatever the user posted in the form).
And that's how I check if its row count:
$column = 'recovery_email';
try
{
$recover->checkInfo('recovery_email', $_POST['email']);
echo
'
<form action="check.php" method="post">
<input type="text" name="id">
<button type="submit" class="btn">Continue</button>
</form>
';
}
catch (Exception $t)
{
echo '<div class="alert alert-error">'.$t->getMessage().', <a href="check.php">Go back</a></div>';
}
Result:
Could not find recovery
- The column names are correct.
- And the Parm is correct (Took it from the database).
Problem:
I am putting the correct information, yet it giving me an error that could not find the row.
Question
Why is it happening?
How can I fix this?