Avatar of ChrisTERiS
ChrisTERiS

asked on 

iFrame with database field value

Hello,

I know how to add an iFrame which will contains a file with "src" tag, but what if I want to show in the iframe a variable which holds the value of a database field?

Thank you
PHPHTML

Avatar of undefined
Last Comment
ChrisTERiS
Avatar of ChrisTERiS
ChrisTERiS

ASKER

Points increased
Avatar of stu215
stu215
Flag of United States of America image

You would put the variable and any content on the source page you referenced in the "src=" part of the iFrame tag.

Avatar of ChrisTERiS
ChrisTERiS

ASKER

Sorry, didn't got your meaning. Let's try with a real example. I've a variable $tos which holds a very long text (a Terms od Use). What I've to do? src="'.$tos.'" dosen't works.

Avatar of stu215
stu215
Flag of United States of America image

ex: Page1

<iframe src="yourPage.php" width="500" height="400">
</iframe>


----------------------------------------------------------
page2 :: yourPage.php


<?php
    phpinfo();
?>

Avatar of stu215
stu215
Flag of United States of America image

using your variable you would put the following in page 2 "yourPage.php" ::



<?php
 echo "$tos"
?>
Avatar of stu215
stu215
Flag of United States of America image

you would also need to include your database query in "yourPage.php"

ASKER CERTIFIED SOLUTION
Avatar of stu215
stu215
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of stu215
stu215
Flag of United States of America image

I have attached two test files to here that you can use as examples and change.
page1.html
yourPage.php
Avatar of ChrisTERiS
ChrisTERiS

ASKER

So, it was only by trick. I thought to have a file working as your example, or even to create at run time a file with the content using fopen(), but I was hoping that maybe should be a special tag of iframe to do all the job.
Avatar of stu215
stu215
Flag of United States of America image

If you have a <form> on the first page you could also pass the variable to the second page and display it without using php.

<form name='form1' action='yourPage.html' method='post' target='<the name of your iframe goes here>'>
<input type='hidden' name='tos' value='my terms of service'>
</form>

Not quite sure why you'd want to do that with something like TOS which i imagine are static?
( Would just be simpler to have an html page containing the TOS load in the iframe if thats what your trying to do )
Avatar of ChrisTERiS
ChrisTERiS

ASKER

You're right, but I'm using to deliver easy to use scripts. So, all legal letters (TOS, Privacy etc etc), are creating in the admincp using a HTML editor, to be easily editable. Otherwise the end user must have even a small knowledge of using text editors and a bit HTML for bold letters, different font size etc.

In any case thank you.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo