Jump to content

Recommended Posts

Hello. Today I'm working on making some text that a user enters (biography) show up as a popup when the button is clicked.

I have managed to make the popup show the box with the title, and close correctly with some external JS and CSS

What I'm failing at, is getting the value from the database. No errors are showing, and no errors in my error log on the hosting.

What confuses me, is that when I put '.$row['bio'].' in other places on the page, then the value will appear, but not for this popup. Any thoughts?

This is the part that is the popup. This is all within the php page inside an echo. If you need to see more, let me know and I will show it :)

<div class="modal" id="modal">
    <div class="modal-header">
      <div class="title">Bio</div>
      <button data-close-button class="close-button">&times;</button>
    </div>
    <div class="modal-body">'.$row['bio'].'</div>
  </div>
<div id="overlay"></div>

 

Link to comment
https://forums.phpfreaks.com/topic/315842-adding-mysql-value-to-popup/
Share on other sites

Is this block of code wrapped in single quotes?  That could be the problem since the php variable reference won't be interpreted if not.  Maybe try this?

echo "<div class='modal' id='modal'>
    <div class='modal-header'>
      <div class='title'>Bio</div>
      <button data-close-button class='close-button'>&times;</button>
    </div>
    <div class='modal-body'>" . $row['bio'] . "</div>
  </div>
<div id='overlay'></div>";

Note how I began the echo with a double quote and swapped all the other doubles for singles.  Now the $row reference will work.  Kind of confused as to what that reference to &times is supposed to be.  Is that supposed to be $times?

13 minutes ago, ginerjm said:

That could be the problem since the php variable reference won't be interpreted if not. 

Yes it will - concatenation is being used.

If, however, it is html code and not something being echoed then it needs to be

<div class="modal-body"> <?= $row['bio'] ?> </div>

 

@ginerjm and @Barand thank you, but I should have told more. What I posted is actually inside an echo already. I just didn't post the whole pages script. I did try it with a double quote instead just to see if that would work but it didnt, it just made the page blank

OH WOW!!!!
I'm giving myself the major stink-eye right now. I'm so sorry to waste everyones time. 

The reason it wasn't working is because I had the WRONG DATABASE AT THE BEGINNING OF THE FILE!!!

Yup, it was looking for something that wasn't there. Good grief. I changed the database info and now it works (face palm to myself)

Hhahahaha

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.