Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to echo the statement [duplicate]

Tags:

php

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 Answers

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');
like image 121
Manav Sharma Avatar answered Feb 19 '26 23:02

Manav Sharma


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

like image 35
Adharsh M Avatar answered Feb 20 '26 01:02

Adharsh M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!