Find the answer to your Linux question:
Results 1 to 4 of 4
Hi There, I have a mysql database that I want to use to store my website content. I also have an online editor. What I want to achieve is that ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User Allblack's Avatar
    Join Date
    May 2003
    Location
    Godzone
    Posts
    416

    PHP: Load html content into an iframe


    Hi There,

    I have a mysql database that I want to use to store my website content.
    I also have an online editor. What I want to achieve is that the web editor loads the page I need to modify. For some reason it does not work when I try to load html content into the editor (iframe).
    However, If I change the field to something that does not contain html it works fine. Any ideas?

    The full code is below but I have a feeling something is wrong in the way I declare my $temp variable or how do my onLoad

    <body onFocus="window.frames['idContent'].document.body.innerHTML = '<? echo $temp; ?>'">

    //Full code

    <? include("../config.php");
    $query="select title,html from content where id=2";
    $result=mysql_query($query);
    while($mydata=mysql_fetch_array($result)){
    $temp= $mydata[html];
    }
    //$num_rows = mysql_num_rows($result);
    ?>
    <script LANGUAGE="JavaScript">
    function button_over(eButton){
    eButton.style.backgroundColor = "#B5BDD6";
    }
    function button_out(eButton){
    eButton.style.backgroundColor = "white";
    }
    function button_down(eButton){
    eButton.style.backgroundColor = "#8494B5";
    }
    function button_up(eButton){
    eButton.style.backgroundColor = "#B5BDD6";
    eButton = null;
    }

    var isHTMLMode=false

    function document.onreadystatechange(){
    idContent.document.designMode="On"
    }
    function cmdExec(cmd,opt) {
    if (isHTMLMode){alert("Please uncheck 'Edit HTML'");return;}
    idContent.document.execCommand(cmd,"",opt);idConte nt.focus();
    }
    function setMode(bMode){
    var sTmp;
    isHTMLMode = bMode;
    if (isHTMLMode){sTmp=idContent.document.body.innerHTM L;idContent.document.body.innerText=sTmp;
    }
    else {sTmp=idContent.document.body.innerText;idContent. document.body.innerHTML=sTmp;
    }
    idContent.focus();
    }
    function createLink(){
    if (isHTMLMode){alert("Please uncheck 'Edit HTML'");return;
    }
    cmdExec("CreateLink");
    }
    function Save() {
    if (isHTMLMode){alert("Please uncheck 'Edit HTML'");return;
    }
    var sImgTag = idContent.document.body.all.tags("IMG");
    var oImg;
    for (var i = sImgTag.length - 1; i >= 0; i--) {
    oImg = sImgTag[i];
    }
    }
    </script>
    <html>
    <body onFocus="window.frames['idContent'].document.body.innerHTML = '<? echo $temp; ?>'">
    <? echo $temp; ?>
    <form method="post" name="content" onsubmit="document.all['description'].value = window.frames['idContent'].document.body.innerHTML;" action="editoutput.php">
    <td class="bodyfont"><table width="100%" border="0" cellpadding="2" cellspacing="0" class="border" id="tblCoolbar">
    <tr>
    <td colspan="13"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="11%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Page
    Title</font></td>

    </tr>
    </table></td>
    </tr>
    <tr>
    <td width="300"><select onChange="cmdExec('formatBlock',this[this.selectedIndex].value);this.selectedIndex=0">
    <option selected>Style</option>
    <option value="Normal">Normal</option>
    <option value="Heading 1">Heading 1</option>
    <option value="Heading 2">Heading 2</option>
    <option value="Heading 3">Heading 3</option>
    <option value="Heading 4">Heading 4</option>
    <option value="Heading 5">Heading 5</option>
    </select> <select onChange="cmdExec('fontname',this[this.selectedIndex].value);">
    <option selected>Font</option>
    <option value="Arial">Arial</option>
    <option value="Arial Black">Arial Black</option>
    <option value="Arial Narrow">Arial Narrow</option>
    <option value="Courier New">Courier New</option>
    <option value="Tahoma">Tahoma</option>
    <option value="Times New Roman">Times New Roman</option>
    <option value="Verdana">Verdana</option>
    <option value="Wingdings">Wingdings</option>
    </select> <select onChange="cmdExec('fontsize',this[this.selectedIndex].value);">
    <option selected>Size</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="10">10</option>
    <option value="12">12</option>
    <option value="14">14</option>
    </select></td>
    <td width="23"><div class="cbtn" onClick="cmdExec('bold')" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);">
    [img]images/Bold.gif[/img]
    </div></td>
    <td width="23"><div class="cbtn" onClick="cmdExec('italic')" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);">
    [img]images/Italic.gif[/img]
    </div></td>
    <td width="23"><div class="cbtn" onClick="cmdExec('underline')" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);">
    [img]images/Under.gif[/img]
    </div></td>
    <td width="23"><div class="cbtn" onClick="cmdExec('justifyleft')" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);">
    [img]images/Left.gif[/img]
    </div></td>
    <td width="23"><div class="cbtn" onClick="cmdExec('justifycenter')" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);">
    [img]images/Center.gif[/img]
    </div></td>
    <td width="23"><div class="cbtn" onClick="cmdExec('justifyright')" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);">
    [img]images/Right.gif[/img]
    </div></td>
    <td width="23"><div class="cbtn" onClick="cmdExec('insertorderedlist')" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);">
    [img]images/numlist.GIF[/img]
    </div></td>
    <td width="23"><div class="cbtn" onClick="cmdExec('insertunorderedlist')" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);">
    [img]images/bullist.GIF[/img]
    </div></td>
    <td width="23"><div class="cbtn" onClick="cmdExec('outdent')" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);">
    [img]images/deindent.gif[/img]
    </div></td>
    <td width="23"><div class="cbtn" onClick="cmdExec('indent')" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);">
    [img]images/inindent.gif[/img]
    </div></td>
    <td width="23"><div class="cbtn" onClick="cmdExec('createLink')" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);">
    [img]images/Link.gif[/img]
    </div></td>
    <td></td>
    </tr>
    </table>
    <iframe width="95%" id="idContent" height="200" ></iframe>
    <input id="description" name="description" type="hidden">
    </td>
    <tr><td><input name="submit" type="Submit" value="Submit"></td></tr>
    <input name="reset" type="reset" id="reset" value="Reset">
    </form>
    I am on a journey to mastering Linux and I got a bloody long way to go!!!

  2. #2
    Linux User Allblack's Avatar
    Join Date
    May 2003
    Location
    Godzone
    Posts
    416
    I do believe now that the problem is lying with the mysql backend.
    I use a text field to store my html and sometimes it seems to work as long as I keep the content relatively short.
    i.e. <h2>my header</h2> .
    It looks it has issues dealing with certain tags such as <hr>,<a href> etc
    I am on a journey to mastering Linux and I got a bloody long way to go!!!

  3. #3
    Linux User
    Join Date
    Aug 2003
    Posts
    289
    i'm no expert but i don't think mysql has anything to do with these HTML tags. as far as it's concerned, it'll treat is as just another entry, like ordinary text.

    and if i'm getting you right (coz i didn't read your code), if you load HTML tags to a browser, the browser will automatically interpret those tags. it has no way of knowing that you didn't want to do this. that's why there are "&lt;" and "&gt;", and etc. PHP also has this .htmlspecialchars (and some other functions for this, i guess) function that will ignore HTML tags when loaded on a browser. i used that function in my guestbook and all entries are stored in a database.
    Registered User #345074

  4. #4
    Linux User Allblack's Avatar
    Join Date
    May 2003
    Location
    Godzone
    Posts
    416
    Apparently it has to do with the speed of loading. That makes sense as there are no issues with short content. I haven't investigated it yet.
    A div tag is supposed to handle this better than an iframe as well.
    I am on a journey to mastering Linux and I got a bloody long way to go!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •