3

How to echo the statement in if condition.

Please refer code

<?php
session_start();
require_once 'class.user.php';
$user_home = new USER();

if(!$user_home->is_logged_in())
{
    $user_home->redirect('<?php echo $web ?>index.php');
}

$stmt = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);

?>

Please correct this

$user_home->redirect('<?php echo $web ?>index.php');

I want to echo $web.

2 Answers2

3

In PHP code you didn't need to echo the variable. You are trying to concatenate a string here using the value in the $web variable. So you can use . to join the strings.

 $user_home->redirect($web.'index.php');
Blueline
  • 388
  • 1
  • 10
Manav Sharma
  • 187
  • 1
  • 8
1

Use

<?php
session_start();
require_once 'class.user.php';
$user_home = new USER();

if(!$user_home->is_logged_in())
{
    $user_home->redirect($web.'index.php');
}

$stmt = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);

?>

You may also refer PHP Concatenation

Adharsh M
  • 2,773
  • 2
  • 20
  • 33