how to insert and iframe from php

6.8k views Asked by At

I have create a form, after details have been submitted I am trying to open an Iframe for the response. But I keep receiving an error in the line in bold. This is my code:

// this code is within my php code

if($result){
**echo <li><iframe width="420" height="315" src="datasave.php" frameborder="0"></iframe></li>**
}
else{
echo"ERROR"
}

datasave.php ==> This is the code in this file

<?php
echo Your details have been sent successfully!;
?>
2

There are 2 answers

1
Quentin On

Either:

Leave PHP mode if you want to go into output mode. You can't just put raw HTML where PHP is expected.

if($result){
?>
    <li><iframe width="420" height="315" src="datasave.php" frameborder="0"></iframe></li>
<?php
}

or

Put delimiters (" or ' usually) around your PHP strings.

if($result){
    echo '<li><iframe width="420" height="315" src="datasave.php" frameborder="0"></iframe></li>'; 
}
0
Yatin Khullar On

Just replace your this line

**echo <li><iframe width="420" height="315" src="datasave.php" frameborder="0"></iframe></li>**

with this one

echo '<li><iframe width="420" height="315" src="datasave.php" frameborder="0"></iframe></li>';