Jump to content

Page Editor, Preview As Change


Spartan 117

Recommended Posts

Hello, I have a simple html editor on my page that edits the left portion of my page. I wanted to know if I could make the left side of the page load the html from the textbox as I change the html in the textbox. Here is my code for the editing and such:

 

 <?php
// Database connection here
include('config.php');
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

$sql = "SELECT * FROM page_links WHERE id='1'";
$res = mysql_query($sql) or die (mysql_error());
$r = mysql_fetch_assoc($res);
$check = mysql_num_rows($res);
// check to make sure your id exists
if($check > 0){
// convert all fields to strip slashes and line breaks to <br>
$links = nl2br(stripslashes($r['links']));
?>
              <p align="center">
                <textarea name="pagelinks" cols="50" rows="20" id="pagelinks"><?=$links ?>
                </textarea>
                <?php
} else {
// show this if ID does not exist
echo "<p align=center><font color=\"FFFFFF\"><b>There is an error in your database.<b></font></p>";
?>
                <?php
}
?>
</p>
              <p align="center">
                <input name="submit" type="submit" id="submit" value="Edit Links">          
                  </p>
            </form>
            <p align="center">
<?php
   if ($_POST['submit'])//($_POST["$submit"])
   {
       $newlinks = $_POST['pagelinks'];
       $sql = "UPDATE page_links SET links='$newlinks' WHERE id='1'";
       $result = mysql_query($sql);
      echo "Links Updated!";
  echo '<META HTTP-EQUIV="Refresh" Content="0; URL=linkeditor.php">';   
}
?>

 

Is it possible to make the links on the left equal the code in the textbox as I change it without submitting?

Link to comment
https://forums.phpfreaks.com/topic/41969-page-editor-preview-as-change/
Share on other sites

Well, since the "left side of the page" is not on the same page as the editor, you can't use any simple JavaScript.  You'd have you implement some AJAX on your editor and display page.  However, that means that if you type something in, it'll update in the database, regardless of whether or not you push submit.  Overall, this is a little impractical.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.