I use the code below to write my HTML content to my MySQL database. The only problem is that it keeps writing 2 records to my MySQL db. One with the correct info the other with the word 'POST'. It goes wrong in the last field wich in the db is defined as Text. Any comment?
if (isset($_POST['newspost'])) { $postArray = &$_POST ; foreach ( $postArray as $sForm => $value ) { if ( get_magic_quotes_gpc() ) $postedValue = htmlspecialchars( stripslashes( $value ) ) ; else $postedValue = htmlspecialchars( $value ) ; $date = date("Y-m-d"); $time = date("H:i"); $query='INSERT INTO news_comment (post, user, date, time, text) VALUES ("'.$_GET['id'].'", "'.$_COOKIE['userid'].'", "'.$date.'", "'.$time.'", "'.$postedValue.'")'; mysql_query($query) or die (mysql_error()); } }
Re: FCK to MySQL
When i print it however, I see the <p> on my screen.
Re: FCK to MySQL
Add these lines to your script:
Re: FCK to MySQL
Re: FCK to MySQL
$postArray = &$_POST ;
by
$postArray = $_POST ;
Re: FCK to MySQL
Re: FCK to MySQL
Re: FCK to MySQL
Re: FCK to MySQL
I've been working on this for about a month now and I haven't been getting a lot of help.
Re: FCK to MySQL
where did you place the code? In what directory? I ask because when I load everything up to my server, I notice that the FCKeditor is within an "iframe".
Re: FCK to MySQL
Re: FCK to MySQL
Fixed it!!!!
Solution can be found here: http://www.cubevision.eu/scripts.php?post=1
Re: FCK to MySQL
if I just enter plain text it all works great getting into my mySQL database. but when I try to add "bold" text, "colored" text, etc. I get this message "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'color: rgb(51, 102, 255);">what happens...
In researching it appears to be a common issue but I have been unable to find the solution. I followed the "...config.js suggestions" since I have a feeling this is a "config" issue but nothing has worked. Did you run into this?
Re: FCK to MySQL
Re: FCK to MySQL
Re: FCK to MySQL
The error is more due to Php. I think you don't escape the input of your query.
You're using double quotes to make your insert-query. When you also have a double quote in your input, mysql thinks this is the end of the query. The words after this "end" aren't commands of mysql, so it doesn't know what to do with it. Which results in an error.
That's why you have to make your input safe for mysql. This you can do by using the php-function mysql_real_escape_string().
If the server has safe_mode() to ON, it's recommended to use strip_tags() to.
So you will have something like this:
Re: FCK to MySQL
Question: now I want to capture at the same time as the FCKeditor input a topic column, title and description field but I keep getting a parse error. Any thoughts? When I fix one line then it points out another and it never gets corrected. Sort of frustrating...
Re: FCK to MySQL
<?php
$con = mysql_connect("yourlocalhost.com","username","password");
if(!$con)
{
die('Could not connect:'.mysql_error());
}
mysql_select_db("your_db_name",$con);
if(isset($_POST['post'])){
$postArray = $_POST['FCKeditor1'];
if(get_magic_quotes_gpc())
$postedValue = (addslashes($postArray));
$mysql_postArray = mysql_real_escape_string($stripped_postArray);
$query='INSERT INTO name_of_table(id_field, text_field)
VALUES("'.$_GET['id'].'","'.$postedValue.'")';
mysql_query($query) or die (mysql_error());
}
?>
Thanks for everyones assistance. Hope this helps.
Re: FCK to MySQL
Re: FCK to MySQL