-2

The code that I'm using

    if ($_REQUEST('addOrEdit') == 'add') {
      $stmt2 = $pdo->prepare("insert into ITEM (tracker, date, significance, obsolete, description,data, programs, topics, lastModifiedBy) values (?,?,?,?,?,?,?,?,?");

//      $stmt2->execute(array($tracker,$_REQUEST['date'],$_REQUEST['significance],$_REQUEST['obsolete'],$_REQUEST['description'], null, $_REQUEST[program],$_REQUEST[topic],null);

    }  

If I comment out the if line and the closing parenthesis, it works (on AWS LAMP instance). But otherwise this is breaking my page, and when I try to load it, I see nothing but a blank page.

Elsewhere on my page I am echoing out the $_REQUEST['addOrEdit'] and it shows add

The problem appears to be with my if usage(?) What am I doing wrong?

ControlAltDel
  • 32,042
  • 9
  • 48
  • 75

3 Answers3

2

You wrote braces to fetch request parameters in if statement. Replace Braces to square brackets.

if ($_REQUEST['addOrEdit'] == 'add') {
Rahul
  • 17,770
  • 7
  • 39
  • 58
0

Besides the syntax error (which may be a typo as your question contains the correct syntax later on), as Rahul has pointed out, you could be more defensive and check the key exists within the array.

if (array_key_exists('addOrEdit', $_REQUEST) && $_REQUEST['addOrEdit'] === 'add') {
steadweb
  • 13,154
  • 3
  • 28
  • 39
0

$_REQUEST is a global variable of type array.Its not a function. You can access the variable using [] not this (). so try this

if($_REQUEST['addOrEdit'] == 'add'){ your code }

devil
  • 24
  • 4