Newbie in need of help databas Output not echoing properly??
Posted: Tue Sep 05, 2006 2:15 pm
Hi guys 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
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...
http://img521.imageshack.us/img521/2966/dbshotdi1.jpg
For my form page i have tinymce setup with the form action set to post to postnews.php like so...
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...
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...
This is what this code is echoing back from my database
http://img399.imageshack.us/img399/8571 ... putgo0.jpg
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?
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.
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...
http://img521.imageshack.us/img521/2966/dbshotdi1.jpg
For my form page i have tinymce setup with the form action set to post to postnews.php like so...
Code: Select all
<form action="postnews.php" method="post">
<div id="elm1" style="width:450px; height:250px">
</div>
<input type="submit" value="Submit">
</form>Here is my code for the postnews.php file...
Code: Select all
<?
$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();
?>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...
Code: Select all
<?
$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);
?>http://img399.imageshack.us/img399/8571 ... putgo0.jpg
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?
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.