Hi guys,

I have a bunch of these articles on my clients website
Articles

I have been working on a html form for editing them. i managed to find a textedit form on hotscripts.com

So far i have managed to get it working...

3 questions i have:

  1. Why dosnt the title text field populate with the full title? "benefits of letting"

  2. How do i pass the article data to the textArea

<html>
<head>
<script language="JavaScript" type="text/javascript" src="richtext.js"></script>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
// Include config file
include('../common.php');
$link = dbConnect();
// Run query to pull news from the database
	$query = "SELECT * FROM scArticles WHERE arID= '$arID'";
	$result = mysql_query($query);     
if (!$result) { fail("Couldn't list Lets from database"); } $let = mysql_fetch_array($result); $arID = $let['arID']; $arTitle = $let['arTitle']; $arNews = $let['arNews']; ?> <body> <form name="form1" method="post" action=""> <table width="500" height="200" border="1" align="center"> <tr> <td height="23" colspan="2">Article title: <input name="textfield" type="text" value=<? echo $arTitle; ?> > </td> </tr> <tr> <td height="141" colspan="2" align="left" valign="top"> <script language="JavaScript" type="text/javascript"> <!-- initRTE("images/", "", ""); // Dosnt work //writeRichText('rte1', '<?php echo $arNews; ?>', 500, 200, true, false); writeRichText('rte1', 'Article should appear here....', 500, 200, true, false); //--> </script> </td> </tr> <tr> <td width="652" height="23">&nbsp;</td> <td width="56"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form>

example

  1. Is it possible to update the exsisting html page on the server.
    Normally i would pull the pages from db as and when required but the client would rarther i use the html pages.

Anyone
thanks
Paul

    Paul Ferrie wrote:

    1. Why dosnt the title text field populate with the full title? "benefits of letting"

    SNIP

    <td height="23" colspan="2">Article title:
    <input name="textfield" type="text" value=<? echo $arTitle; ?> >

    Try this, putting the value in quotation marks:

    value="<? echo $arTitle; ?>"> 

      Looking at the generated HTML should give you a clue:

        <table width="500" height="200" border="1" align="center">
          <tr>
            <td height="23" colspan="2">Article title:
              <input name="textfield" type="text" value=benefits of letting >
      
      
      </td>

        Title i am sure i will get sorted. The main issue is passing the php var to the js script. so that the text area is populated with the relevent article

          What do you mean

          // Dosnt work
          //writeRichText('rte1', '<?php echo $arNews; ?>', 500, 200, true, false);

          ? What does the generated HTML look like (and if you'd looked at this before you'd have seen what was wrong with the title, as well).
          Probably a lack of htmlentities. Check the function's documentation to see what escaping is involved.

            Paul Ferrie wrote:

            Title i am sure i will get sorted. The main issue is passing the php var to the js script. so that the text area is populated with the relevent article

            I am not sure, have you tried something as simple as this:

            <script language="JavaScript" type="text/javascript">
            <textarea name="news"><?php echo $arNews; ?></textarea>
            </script> 

            Also, have you tried to echo out the vaule elsewhere on the page to know it is not empty?

              Rodney H. i know that the var is being passed ok because arTitle is pulled from the same query.
              I dont know how the JS worsk. It's a rich text editor i got off hotscripts.com

                I was looking on dynamic dive web site where you possibly downloaded this, and looked at the source code for the demo. I thought maybe you have a single quote in your string before any output, so, Try this:

                writeRichText('rte1', '<?php 
                
                echo htmlentities($arNews, ENT_QUOTES); // maybe this will help
                
                ?>', 500, 200, true, false); 

                  It's seems that the data is loading fine acordding to view source. There seems to be some kind of conflict happening but it is behound me.

                  data being puled from the db does contain html tags

                    Have you tried stripping all the tags with PHP before entering it? (just out of curiousity)

                      No that would defeat the purpose of what i am trying to do.

                        My next question is.

                        Is it possible to right an hmtl page or update an exsisting html page on there server were as before i would just update the database.

                        Thanks

                          Certainly, you'd just write the HTML into a file instead of into a database. There's nothing in this code that stops you from doing anything you want with the submitted HTML or stops you from getting it from wherever you've got it.

                            How do i go about creating the html page and saving or over-writing an existing page?
                            It's somethimg i have never had to do.

                            thanks
                            Paul

                              I think you could use fopen and fwrite in this case to overwrite the file's contents:

                              <?php
                              // select file
                              $file = 'YourFileName.php';
                              
                              // select info to update file with as variable
                              $string = $updated_html_file; 
                              
                              // If file exists and is writable
                              if (is_writable($file)){
                              
                              // Open $file in write mode or exit
                              if (!$handle = fopen($file, 'w')){
                              echo 'Cannot open file ('.$file.').';
                              exit;
                              }
                              
                              // Write $string to our opened file or exit
                              if (fwrite($handle, $string) === FALSE){
                              echo 'Cannot write to file ('.$file.').';
                              exit;
                              }
                              
                              echo 'Success. The file, '.$file.', was appended with '.$string.'.';
                              // close file handle
                              fclose($handle);
                              }
                              
                              else {
                              echo 'The file '.$file.' is not writable.';
                              }
                              ?>

                                Paul, make sure you open the file in 'w' mode (overwrite) rather than 'a' (apend) to completely overwrite the file with the new contents. I edited the code above....

                                :- )

                                  Thanks.

                                  If the file does not exsist will it be created?