-2

i'm trying to do this:

function myFunction($id, $id2) {
  $cl=$dbh->prepare("SELECT id2 FROM users WHERE id = :id");
  $cl->bindParam(':id', $id);
  $cl->execute();
  $cli=$cl->fetch(PDO::FETCH_ASSOC);
  $lid=$cli['id2'];
  if($id !== $id2) {
    exit("mismatch error");
  }
}

then i want to call myFunction on another page.

myFunction($id, $id2);

how can i do this correctly on another page?


let me explain better. here is what im trying to do.

i have been putting this on every page:

$cl=$dbh->prepare("SELECT id2 FROM users WHERE id = :id");
  $cl->bindParam(':id', $id);
  $cl->execute();
  $cli=$cl->fetch(PDO::FETCH_ASSOC);
  $lid=$cli['id2'];
  if($id !== $id2) {
    exit("mismatch error");
  }
}

but how would i make that into a function?

johnjay22113
  • 133
  • 3
  • 10

1 Answers1

0

Include the file where your function is located.

<?php
include 'functionFile.php';
echo myFunction($id, $id2);
?>