add and edit text content

Hello all,
I am beginner in php and I have a few quenstions for my current project. I am working on basic php system that an editor add and edit text content (the website is designed for articles ).

add.php

Title
Description
Text
[php] { //insert data to database $result=mysql_query("INSERT INTO content(title,descrip,text) VALUES('$title','$descrip','$text')"); header("Location:member-index.php"); } [/php]

edit.php

Title >
Description >
Text id="edit_tx">
>
[php] $id = $_GET['id']; //selecting data associated with this particular id $result=mysql_query("select * from content where id=$id");

while($res=mysql_fetch_array($result))
{
$title = $res[‘title’];
$descrip = $res[‘descrip’];
$text = $res[‘text’];
}
[/php]

index.php
[php]
echo “

”;

while($res=mysql_fetch_array($result)){

echo "<hr><h2>".$res['title']."</h2>";
echo "<h3>".$res['descrip']."</h3>";
echo "<pre>".$res['text']."</pre>";	
echo "<a href=\"edit.php?id=$res[id]\">Edit</a> | <a href=\"delete.php?id=$res[id]\">Delete</a><hr>";

}
echo “

”;

[/php]
My question is: Is it correct to use only tag for the form or I can use tag for adding and editing the content? Because when is - it doesn not show the whole content, and if I use - when I edit it doen’t show nothing.

My other question is: How can I format the the data (the text) in the index.php? I tryed to format the text with css, but always the text is showed in one line.

Thanks in advance!

Hello,

for large amount of data is better to use textarea, you use it the same way as input type=“text”

to format the data when you retrieve from the database you can use [php]nl2br($rows[‘Examples’])[/php]

this will retrieve it the same way you enter it

Well, Wilson is correct. If you have a large amount of data, you should use TextArea tags. But, when converting the values of them, you have to convert tags to database format if you want to store them inside of MySQL databases or others. I have found after months of experiments that there is a very nice solution to this process. I use an add-in called TinyMCE. It is a simple to add in and simple to use plug in. Basically, download it, copy it to your site and make a few small configuration options. You can add all kinds of options such as BOLD, ITALICS, and a ton of others… Oh, you are using a similar version as we speak… Look above at the options you can do in this text-area!!!

So, here is a link to cover it. By the way, it automatically saves to a MySQL database and converts all of the needed tags for you without any extra code. So, WHAT-YOU-SEE-IS-WHAT-YOU-GET… Try it out!!!
http://www.tinymce.com/tryit/full.php
(Go to the download area!)
AND, it is totally FREE… I have customized it in a TON of ways… Real nice for free!

It is work when the the values are out of the tag for the form:

   <textarea type="text" name="text" value=<?php echo $text;?>><?php echo $text;?></textarea>

but for

tag I used
[php]
echo “

”.nl2br($res[‘text’])."

";
[/php]

Thanks :slight_smile:

Perhaps I did not understand your question… Your textarea code is incorrect.
You had:
[php]
<textarea type=“text” name=“text” value=<?php echo $text;?>><?php echo $text;?>
[/php]
It should be more like this:
[php]
<?php echo $text;?>
[/php]
You do not set a value in textarea, just place the text inside the tags. You still can read it using the textarea’s “name” field which returns the text between the tags.

nl2br is fine for what he needs for now because he only storing texts

ErnieAlex, What you recommended looks pretty advanced and useful when you need to store formatted html

Thanks

Yes, Wilson, but, he mentioned using CSS to format the text. Therefore, he might be interested in something more advanced. But, if not, “nl2br” will work just fine! I agree. Hard to know what someone really wants help with…

I agree

Sponsor our Newsletter | Privacy Policy | Terms of Service