0

I am trying to display a pages ID which is created from a table field. Currently I have this setup

    if (isset($_GET['id']))
   {
   $Id = $_GET['id'];
   }
else
   {
   $Id = '147';
   }

This works great when I echo $Id However the $Id needs to contain the text from a predetermined table field named $extra1. So I used the code

if (isset($_GET['id']))
   {
   $Id = $_GET['id'];
   }
else
   {
   $Id = '$extra1';
   }

When I now echo $Id it simply says $extra1 - and not the actual content of that field. The field "extra1"will always be a 3 digit number and so when I echo $Id, it should display 222 for example

I hope you guys understand what I'm trying to do and look forward to any help

Thanks

Jason

3 Answers3

1

change it like this

      $extra1='123' //example 
      if (isset($_GET['id']))
      {
        $Id = $_GET['id'];
      }
      else
      {
        $Id = $extra1;
      }
404 Not Found
  • 1,223
  • 2
  • 22
  • 31
0

Just try with:

if (isset($_GET['id'])) {
   $Id = (int) $_GET['id'];
} else {
   $Id = $extra1;
}

Or even faster:

$Id = isset($_GET['id']) ? (int) $_GET['id'] : $extra1;
hsz
  • 148,279
  • 62
  • 259
  • 315
0

Try this

$Id = "$extra1";

OR

$Id = $extra1;
웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91