-1

I am trying to update a session value($_SESSION['adtitle']) based on another session value($_SESSION['amount']) with following code.It works for first time page load but then after it doesn't update the session accordingly though my main session $_SESSION['amount'] is updating

<?php
 session_start();
 if (isset($_SESSION['amount'])) {

 if($_SESSION['amount']=2)
 $_SESSION['adtitle']="Premium Listings for $2";

 else if ($_SESSION['amount']=4)
 {$_SESSION['adtitle']="Premium Blogs for $4";}

 } else {
 $_SESSION['adtitle']="Pls select your purchase type again!!";
 }
 header('Location: '. $_SERVER['HTTP_REFERER'] . '');
?>
Mithu
  • 665
  • 1
  • 8
  • 38
  • You forget the second "=" on your statements. – Obzi Oct 31 '17 at 11:01
  • 1
    `if ($_SESSION['amount']=2)` needs to be `if ($_SESSION['amount'] == 2)`, and same for the other `if` as well. `=` sets a value, whereas `==` and `===` compare values. – ADyson Oct 31 '17 at 11:02
  • changed but same result. first time it works then after it doesn't update though $_SESSION['amount'] value is changed – Mithu Oct 31 '17 at 11:05

1 Answers1

0

missing = on comparison. I have fixed the issue

<?php
 session_start();
 if (isset($_SESSION['amount'])) {

 if($_SESSION['amount']==2)
 $_SESSION['adtitle']="Premium Listings for $2";

 else if ($_SESSION['amount']==4)
 {$_SESSION['adtitle']="Premium Blogs for $4";}

 } else {
 $_SESSION['adtitle']="Pls select your purchase type again!!";
 }
 header('Location: '. $_SERVER['HTTP_REFERER'] . '');
?>
Bilal Ahmed
  • 4,005
  • 3
  • 22
  • 42
  • changed it accordingly but yet same result for first time it updates then after it doesn't – Mithu Oct 31 '17 at 11:04