Database integration

Last post 03-21-2011, 7:48 AM by pbrad. 3 replies.
Sort Posts: Previous Next
  •  03-16-2011, 9:25 AM 66689

    Database integration

    Hi,
    Does anyone have any tips on how to use CuteEditor to replace an instance of a textarea that is already connected to a database field?
    thanks for any help.
    Pete 
  •  03-17-2011, 3:57 PM 66724 in reply to 66689

    Re: Database integration

    So nobody has ever done this...?
  •  03-18-2011, 8:14 AM 66738 in reply to 66724

    Re: Database integration

    Dear pbrad,
     
    Sql Server example:
    <?php include_once("cuteeditor_files/include_CuteEditor.php") ; ?>
    <html>
    <head>
    </head>
    <body>
    <form name="theForm" action="11.php?postback=true" method="post"><?php
    function getData()
    {
        $conn=mssql_connect("127.0.0.1","cute","cute");
     $db=mssql_select_db("cuteeditortest", $conn);
     $sql = "SELECT ID, content FROM acid";
     $res = mssql_query($sql);
     $row = mssql_fetch_array($res); 
        $data = $row['content'];
      //echo("<script type='text/javascript'>");
      //echo("alert('$data')");
      //echo("</script>");
     mssql_close();
     return $data;
    }
    function writeData($content)
    {
     $conn=mssql_connect("127.0.0.1","cute","cute");
     $db=mssql_select_db("cuteeditortest", $conn);
     $sql = "INSERT INTO acid(id, content) values ('55','$content')"; 
     $res = mssql_query($sql);
     mssql_close();
    }
    ?>
    <?php
    $editor=new CuteEditor();
    $editor->ID="Editor1";
    $editor->UseHTMLEntities=false;
    $editor->EditCompleteDocument=true;
    if (@$_GET["postback"]!="true")
    {
     $editor->Text = getData();
     $editor->Draw();
    }
    else
    {
     writeData($_POST["Editor1"]);
     $editor->Text = $_POST["Editor1"];
     $editor->Draw();
    }
    $editor=null;
    //use $_POST["Editor1"]to retrieve the data
    ?> <textarea name="textbox1" rows="2" cols="20" id="textbox1"
     style="font-family: Arial; height: 250px; width: 730px;">
    <?php echo @stripslashes($_POST["Editor1"]) ;?>
                </textarea></form>
    </body>
    </html> 
    MySQL example:
    <?php include_once("cuteeditor_files/include_CuteEditor.php") ; ?>
    <html>
    <head>
    </head>
    <body>
    <form name="theForm" action="1.php?postback=true" method="post"><?php
    function getData()
    {
     $cnx = mysql_connect('localhost','root','');
     mysql_select_db('cuteeditortest');
     $records = @mysql_query('SELECT ID, content FROM acid');
     if (!$records) {
      return "data is empty";
     }
     if ($record = mysql_fetch_array($records)) {
      $id   = $record['ID'];
      $content = $record['content'];
      return $content;
     }
    }
    function writeData($content)
    {
     $connect = @mysql_connect( "localhost", "root", "" );
     if ( ! $connect ) {
      die( "Couldn't connect to MySQL: ".mysql_error() );
     }
     $db = "cuteeditortest";
     @mysql_select_db( $db ) or die ( "Couldn't open $db: ".mysql_error() );
     $sql = "INSERT INTO acid( id, content ) values ('55','$content')";
     mysql_query( $sql, $connect ) or die ( "INSERT error: ".mysql_error() );
     mysql_close( $connect );
    }
    ?> <?php
    $editor=new CuteEditor();
    $editor->ID="Editor1";
    $editor->EditCompleteDocument=true;
    if (@$_GET["postback"]!="true")
    {
     $editor->Text = getData();
     $editor->Draw();
    }
    else
    {
     writeData($_POST["Editor1"]);
     $editor->Draw();
    }
    $editor=null;
    //use $_POST["Editor1"]to retrieve the data
    ?> <textarea name="textbox1" rows="2" cols="20" id="textbox1"
     style="font-family: Arial; height: 250px; width: 730px;">
    <?php echo @stripslashes($_POST["Editor1"]) ;?>
                </textarea></form>
    </body>
    </html>
     Thank you for asking
  •  03-21-2011, 7:48 AM 66772 in reply to 66738

    Re: Database integration

    Perfect, thanks. I will use the info above to try and get it working inside the Codecharge environment.
    Cheers,
    Pete 
View as RSS news feed in XML