James James - 1 year ago 77
PHP Question

Issue passing variable using isset()

Would really appreciate it if someone could point me in the right direction.

I am starting to learn PHP again as I have not touched it for years.

Below is a snippet of code I have wrote for a Message System.


$stmt = $user_home->runQuery("SELECT * FROM tbl_messages WHERE recipientID=:uid");
while ($qryMessages = $stmt->fetch(PDO::FETCH_ASSOC))

$mID = $qryMessages['msgID'];
$mTitle = $qryMessages['msgTitle'];

echo "<td><a href='?read&mID=$mID'>" . $mTitle . "</a></td>";


Some HTML here etc....


if(isset($_GET['read&mID=' . $mID]))
echo $mID

I want to be able to show the message on the same page by using isset() but cannot seem to pass the $mID variable to it when its clicked, I keep receiving this message: Notice: Undefined variable: mID in D:\xampp\htdocs\development\template\home\messages.php on line 234

Any feedback would be greatly appreciated.

Answer Source

In the $_GET array, you can specify the query string parameter keys. Here, the query string keys are read and mID. Please note that $mID is the value, so we need not mention it in the isset() function.

You could replace this with:

if (isset($_GET['mID'])) {
   echo $_GET['mID'];                 // This will print the value of $mID
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download