I am building an online WYSIWYG editor, and I have constructed a method for clients to edit their own webpages through a <textarea>
method in HTML. Now the only issue is that I have never dealt directly with databases (when I say 'never' I mean... never.)
I am seriously stuck on a few things about this... I'm hoping someone knows how to fix this.
So, code is as follows:
(all of this is within the body tags...)
<!-- Database Connection -->
<?php
if ($_POST['submit']) {
// MySql Database Connection, connecting at ("?", with details "user", "password") or spit error
mysql_connect ("localhost", "user", "password") or die ('Error: ' . mysql_error());
// Select database named ("dbName") or spit error
mysql_select_db("dbName") or die ('Data error:' . mysql_error());
// Select text to input, from textarea, name="textName"
$text = mysql_real_escape_string($_POST['textName']);
// Input ^ into table "TableName", field (field)
$query="INSERT INTO TableName (field) VALUES ('$text')";
// Submit query, or spit error
mysql_query($query) or die ('Error updating database' . mysql_error());
}
?>
<!-- Actual Text Input -->
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<textarea name="textName">INITIAL TEXT</textarea>
<input name="submit" type="submit" value="submit" />
</form>
The actual code for pushing information into the database is working, I can very easily input text into the textarea and click submit and then look at it inside the database I have setup- however I now need to take the information out of the database.
I need to pull it out in two ways:
- To display it onto the webpage (which will be done on another document to this) AND
- To display it inside the textarea, replacing the "INITIAL TEXT".
(If any of the code looks like it shouldn't work then it is probably because I have quickly removed information about the actual server).