mardi 25 février 2020

My PHP Variable that I pulled from a MySQL database keeps returning undefined

hope all is well.

I have had a bit of an issue this evening when I was working on a message system for some project for work. I'm working on the inbox, and have it set up so that it pulls the message subject, sender, and date of sending in table rows on the front-end. That all works great. My issue is pulling the message body, which is the actual message content. It's supposed to show up in a modal when the table rows are clicked in the front-end, and I can get that to work without issue. The problem is that I can't pull a non-undefined variable for the message content in the first place.

My SQL table looks like this:

msgTo (text), msgFrom (text), msgSubject (text), msgMessage (text), msgDate (text)

My PHP code looks like this:

                $msgTo = $row["msgTo"];
                $msgFrom = $row["msgFrom"];
                $msgSubject = $row["msgSubject"];
                $msgTime = $row["msgTime"];
                $msgDate = $row["msgDate"];
                $msg = $row["msgMessage"];

If I echo or print any of the variables other than my $msg variable, it works great. But no matter what I try, my $msg variable returns undefined.

The content for the "msgMessage" column in the MySQL table is the following:

"Hello John,

How's it going?"

My best guess is that because unlike all the other variables I'm pulling, this one has line breaks, and maybe it can't handle the equivalent of "\n"? So maybe there is some sort of way I need to sanitize it.

Thanks in advance. Please let me know if there is more information you need.




Aucun commentaire:

Enregistrer un commentaire