I have this piece of code:
private function grabCurrentUser() {
$this->id = parent::secure($_GET['cid']);
$params = array( ':user_id' => $this->id );
$stmt = parent::query("SELECT * FROM users WHERE user_id = :user_id;", $params);
if( $stmt->rowCount() < 1 ) parent::displayMessage("<div class='alert alert-error'>"._('No such user!')."</div>");
foreach ($stmt->fetch(PDO::FETCH_ASSOC) as $field => $value)
$this->options[$field] = $value;
}
I want to replace the error message on it, so instead of having this error message:
parent::displayMessage("<div class='alert alert-error'>"._('No such user!')."</div>
I want to include index.php like so:
include_once(cINC . 'index.php');
So how can I replace it from showing an error message to just including index.php?
I tried this:
private function grabCurrentUser() {
$this->id = parent::secure($_GET['cid']);
$params = array( ':user_id' => $this->id );
$stmt = parent::query("SELECT * FROM users WHERE user_id = :user_id;", $params);
if( $stmt->rowCount() < 1 ) include_once(cINC . 'index.php');
foreach ($stmt->fetch(PDO::FETCH_ASSOC) as $field => $value)
$this->options[$field] = $value;
}
But got this error:
Warning: Invalid argument supplied for foreach()
Thanks in advance
You had mistake in application logic, if you don’t have any records and want to include some file then you don’t iterate through empty record list.