Jump to content


Photo

Integrating wysiwyg outputting numbers instead of content! newbie in need of hel


  • Please log in to reply
4 replies to this topic

#1 EvoDan

EvoDan
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 September 2006 - 12:50 AM

Wassup peeps! this looks like a great board to be a part of and i am hoping to learn a thing or two about php from here, but i have a feeling it is going to be a looong journey ;D.

I have been trying to set up a simple Content management system for a client using tinymce as the main editor form, but as i'm a total newbie and have just started learning php its proving quite difficult for me. What i have managed to do so far seems to be ok except the output on my public page echoed from my database isnt working right at all. So i was hoping somone here can take a look at my scripts and tell me whats right and wrong or point me in the direction of a tutorial that might help me.
so here is what i have so far....

I created a database with phpmyadmin called "boarhunt" and a table named "news" with two fields these are set like so..

1. id, int, (11), not null, primary key.
2.content, text, not null, default.

So it looks like this...
Posted Image

For my form page i have tinymce setup with the form action set to post to postnews.php like so...
<form action="postnews.php" method="post">
        <div id="elm1" style="width:450px; height:250px">
       
       
   </div>
<input type="submit" value="Submit">
    </form>

There is also some javascript in the head of the page to create the wysiwyg editor in the page where the id elm1 appears.

Here is my code for the postnews.php file...

<?
$username="******";
$password="******";
$database="boarhunt";
$host="localhost";

if(isset($_POST['save']))

$content=$_POST['content'];


mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

{
$query = "insert into News (id,content) values ('','$content')";
mysql_query($query) or die(mysql_error('Error Query Failed'));

echo htmlspecialchars($query);
}


mysql_close();
?>

This seem all well and good as it seems to be posting to the database ok as everytime i submit something it adds rows to the database
and it increases in size so i assume that part is working, but if there is anything odd about it please let me know?


Next (and this is where i have hit a brick wall) i have tried to write an output script to go on my public pages to display the edited content
but all i get back is a bunch of numbers.

here is the script for my public page...

<?
$host="localhost";   
$username="******";
$password="******";
$database="boarhunt";



$db = mysql_connect($host,$username,$password);
@mysql_select_db($database) or die("Unable to select database");


$result = mysql_query("SELECT * FROM news");
while($row = mysql_fetch_array($result))
{
echo $row['id'] . " " . $row['content'];
}
@mysql_close($db);
?>

This is what this code is echoing back from my database

Posted Image

So what i would like to know is how do i get the page to display the content i entered into the wysiwyg editor instead of those numbers?
And where am i going wrong with my script?
Are there any tutorials for coding a wysiwyg editor to work with a mysql database that i can follow?

Many thanks in advance to anybody who can help me out with this as i have been scratching my head over this for a week now and i have gotten as far as i can on my own with this. 

#2 emehrkay

emehrkay
  • Staff Alumni
  • Advanced Member
  • 1,214 posts

Posted 07 September 2006 - 01:26 AM

doesnt tiny mce requre a textarea in the form? maybe that is your problem, i dont see one

#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 07 September 2006 - 01:34 AM

Tiny can be configured to use a div instead of text area...

I really can't see anything amiss with that code - what EXACTLY is stored in the content field of teh database?

Or can you copy and paste the html generated by echoing out this info..


follow me on twitter @PHPsycho

#4 EvoDan

EvoDan
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 September 2006 - 01:46 AM

Well i was hoping that the text i have put into the editor was going to be stored in the content field, how do i check? I'm not sure i follow what you mean by copy and pasting the html generated by this?
Do you mean from the page source in my browser, or from the database itself?

#5 EvoDan

EvoDan
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 September 2006 - 12:35 PM

doesnt tiny mce requre a textarea in the form? maybe that is your problem, i dont see one


You mentioning that has made me think of something and i was wondering if this would work?

If i build a cms from a tutorial like this...
http://www.devshed.c...m-in-PHP-MySQL/

And then put tinymce (replace text area method) in to replace the normal text area in the tutorial would tinymce work with all its functionality along with the rest of the code?

Or would it require some extra php coding to get it going?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users