1

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.

<?php


$stmt = $user_home->runQuery("SELECT * FROM tbl_messages WHERE recipientID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
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....

<?php 

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 error message:

Notice: Undefined variable: mID in D:\xampp\htdocs\development\template\home\messages.php on line 234

Any feedback would be greatly appreciated.

2 Answers 2

2

You have to use isset like this

<?php 

if(isset($_GET['mID']))
 {
    echo $_GET['mID'];
 }
?>

PHP manual

Sign up to request clarification or add additional context in comments.

Comments

1

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
}

1 Comment

Thank you for your explaination, completely see where I've gone wrong. Makes perfect sense to me now. Thanks again

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.