htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 3 (beta): htmlArea 2 & 3 archive (read only): htmlArea v3.0 - Discussion:
Updating Information to MySQL


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


antonitus
Novice

Aug 10, 2004, 7:49 AM

Post #1 of 21 (6942 views)
Shortcut
Updating Information to MySQL Can't Post

Hi,

I managed to output the results of the editor in PHP and in a MySQL database, however I'm having major problems updating the information in the database. I've tried using the normal UPDATE syntax but without any success. I can however select an id with certain information in that database but it doesn't seem to update it, i.e. it does nothing.

Here is the syntax:

$sql = "UPDATE table SET ta='$ta' WHERE id=$id";

If I was to replace id=with an id number in the database such as id='83', it then updates that id in the database without any problems. Somehow it doesn't like the above syntax, although this works in my other scripts that just use the normal textarea tags.

Does anyone have a suggestion?

Regards,
Tony


Ice^3
Novice

Aug 10, 2004, 11:53 AM

Post #2 of 21 (6931 views)
Shortcut
Re: [antonitus] Updating Information to MySQL [In reply to] Can't Post

It works when you manually put in "83" but not when you use a variable? It sounds like your variables arent set correctly - try printing them out before you call the sql query.

Also, what is the error you are getting from the sql query. Try printing it out with mysql_error();

And lastly, make sure your input does not have any single quotes that aren't escaped in it, or your query will break.


antonitus
Novice

Aug 10, 2004, 12:22 PM

Post #3 of 21 (6930 views)
Shortcut
Re: [Ice^3] Updating Information to MySQL [In reply to] Can't Post

Hi Ice^3,

Thank you for your reply.

The starnge thing is, I don't get an error message. This is some of the code:Quote


Code
 { 
$db = mysql_connect("localhost","$username","$password");
mysql_select_db("hive",$db);
$sql = "UPDATE table SET ta='$ta' WHERE id='$id'";
$result = mysql_query($sql) or die (mysql_error());
echo "Thank you! Information updated.\n";
}

I get the echo message, above when I click on the submit button that is directed to the above update code.

When you say 'input' do you mean the data in the HTMLArea editor box? If so, I have stripslashes which deal with these quotes as I already tested it all. For testing I don't add quotes. The data is outputted in my web pages, i.e. PHP pages and the data gets INSERTed into the MySQL database, but it refuses to be updated.

You may be right to say that I have a problem with my variables, however this code works well in another script I worked on. May be it doesn't like the id variable when I'm using the editor.

I'm a novice at this and PHP. I'm pulling my hair out with this. Do you know of any code that may work with this or more help on what the problem can be?

Regards,
Tony


Ice^3
Novice

Aug 10, 2004, 2:16 PM

Post #4 of 21 (6928 views)
Shortcut
Re: [antonitus] Updating Information to MySQL [In reply to] Can't Post

Between the line where you set $sql and where you call the db query, try dying on $sql. This will show you exactly what the query is (and hence, what all the variables are). If you dont want to die, you can just echo it, and continue on.


antonitus
Novice

Aug 10, 2004, 2:39 PM

Post #5 of 21 (6925 views)
Shortcut
Re: [Ice^3] Updating Information to MySQL [In reply to] Can't Post

Hi,

Do you mean like this:


Code
 { 
$db = mysql_connect("localhost","$username","$password");
mysql_select_db("hive",$db);
$sql = "UPDATE hivetable SET ta='$ta' WHERE id='$id'" or die (mysql_error());
$result = mysql_query($sql) or die (mysql_error());
echo "Thank you! Information updated.\n";
}



I'm trying everything possible (everything that I know) and I cannot seem to resolve it. I'm not getting any errors and I have full privileges on the database. Everything else is perfect so I don't know what it can be, I'm lost and so confused. Unsure I need some serious help. How can I exactly parse a variable? This must be the problem.

Thanks


Ice^3
Novice

Aug 10, 2004, 3:07 PM

Post #6 of 21 (6924 views)
Shortcut
Re: [antonitus] Updating Information to MySQL [In reply to] Can't Post

No, i mean like:


Code
$db = mysql_connect("localhost","$username","$password");  
mysql_select_db("hive",$db);
$sql = "UPDATE table SET ta='$ta' WHERE id='$id'";
echo '----<br /><pre>'.$sql.'</pre><br />----';
$result = mysql_query($sql) or die (mysql_error());
echo "Thank you! Information updated.\n";



antonitus
Novice

Aug 10, 2004, 4:09 PM

Post #7 of 21 (6919 views)
Shortcut
Re: [Ice^3] Updating Information to MySQL [In reply to] Can't Post

Hi Ice^3

This is what I got after I clicked on the submit button:

----
UPDATE table SET ta='Test MM ' WHERE id=''


----Thank you! Information updated.

I can see that id does not have a number, so it definitely is a problem with the variable $id. Any thoughts on how I can tackled this variable would be much appreciated.

Regards,
Tony


Ice^3
Novice

Aug 10, 2004, 4:25 PM

Post #8 of 21 (6917 views)
Shortcut
Re: [antonitus] Updating Information to MySQL [In reply to] Can't Post

Well, from the code you posted, $id is never set. I assumed you set it somewhere else, but that appears to not be the case. All you have to do is set $id to whatever row you want to change.


antonitus
Novice

Aug 10, 2004, 4:34 PM

Post #9 of 21 (6916 views)
Shortcut
Re: [Ice^3] Updating Information to MySQL [In reply to] Can't Post

Thanks for the info. I don't really know how to set $id. Can you please help me with this?

Regards,
Tony


Ice^3
Novice

Aug 10, 2004, 5:10 PM

Post #10 of 21 (6914 views)
Shortcut
Re: [antonitus] Updating Information to MySQL [In reply to] Can't Post

Heh, well...I have no idea what you want to do with your project, so i guess...no...i can't help you. You've got to determine what you want to set id to, based on whatever else is happening with your program.

If you are just wondering how to set id, its just:

Code
$id = 84;

to set $id to the value 84.


antonitus
Novice

Aug 10, 2004, 5:25 PM

Post #11 of 21 (6913 views)
Shortcut
Re: [Ice^3] Updating Information to MySQL [In reply to] Can't Post

Ok, I see what you mean. No, that's not a good way of doing it as the id number is always incremented and can be deleted.

I really appreciate your help in all of this. At least we established that the id does not seem to be set or called for updating the database. The rest of the MySQL insert, select and delete functions work very well.
I basically want to insert/update/delete information on web pages via the database. I already have this working by using just plain textarea and input boxes but as soon as I added the HTMLArea system, everything works well except updating the database.

Thanks,
Tony


antonitus
Novice

Aug 10, 2004, 7:44 PM

Post #12 of 21 (6904 views)
Shortcut
Re: [Ice^3] Updating Information to MySQL [In reply to] Can't Post

Hi Ice^3,

I finally found a solution. It took me most part of the day but I managed to do it thanks to you giving me the idea. I learnt a lot today about debugging. I have learnt how to debug properly as it is important. Well anyway, this is how I resolved it to help other people on the forum.

In the main submissiom htmlArea page, I set the id by adding the following line:

<input type="hidden" name="id" value="<?php echo "$id"?>">

This seems to set the current id of the row in the database and it works a treat. You can also show this to allow people to see what id in the database is being updated if one was to use the GET method in the form.

I added the code (in red) in the following part of the HTML code in the submission form:


Code
   

<!-- Start - Update Form -->
<!-- use <body onload="HTMLArea.replaceAll()" if you don't care about customizing the editor. It's the easiest way! :) -->
<body onload="initEditor()">
<form action="<?php echo $PHP_SELF?>" method="post" idxx="edit" name="edit">
<textarea id="ta" name="ta" style="width:100%" rows="20" cols="40"><?php echo stripslashes($myrow["ta"])?></textarea>
<br> <br>
<input type="submit" name="update" value=" update " />
<input type="hidden" name="id" value="<?php echo "$id"?>">
<input type="button" name="ins" value=" insert html " onclick="return insertHTML();" />
<input type="button" name="hil" value=" highlight text " onclick="return highlight();" />
<a href="javascript:mySubmit()">submit</a>
<script type="text/javascript">
function mySubmit() {
//document.edit.save.value = "yes";
document.edit.onsubmit(); // workaround browser bugs.
document.edit.submit();
};
</script>
</form>

<!-- End - Update Form -->



Regards,
antonitus


(This post was edited by antonitus on Aug 20, 2004, 4:05 PM)


mycs
Novice

Sep 22, 2004, 10:26 AM

Post #13 of 21 (6528 views)
Shortcut
Re: [antonitus] Updating Information to MySQL [In reply to] Can't Post

Hi,

Can you tell me how do you do your sql to insert or update using the textarea content please.

I have a textarea named ta, when i do the insert statement it seems to be ok, but when i check into the data base the row has no value Unsure



Thanks

mycs


antonitus
Novice

Sep 22, 2004, 10:44 AM

Post #14 of 21 (6525 views)
Shortcut
Re: [mycs] Updating Information to MySQL [In reply to] Can't Post

Hi mycs,

When you say the database has no value, what do you mean? What has no value, the id, is the row empty when you try to update? I need more detailed information in order to resolve this. I see you have no trouble with the insert statement. Do you also have an 'update' statement in your SQL to allow for updated information? If not then your row will most certainly be empty.

Tony


mycs
Novice

Sep 22, 2004, 11:34 AM

Post #15 of 21 (6523 views)
Shortcut
Re: [antonitus] Updating Information to MySQL [In reply to] Can't Post

When i say it has no value i mean the row.

this is part of my code:





<form name="form" method="POST" action="<?= $_SERVER["PHP_SELF"]; ?>" onSubmit="return validateform(this);">

<TEXTAREA id="ta" rows="15" cols="50" name="ta"></TEXTAREA>

<input type="submit" name="btnbutton" value="Crear">

</form>

At the bottom of my code i do this:

if ($_POST["btnbutton"]) {

$objCP -> db -> mtdExecuteSQL("INSERT INTO question VALUES(null,$varIDA,'$varIDT','$varIDTAlt',".'"'.$_POST["ta"].'"'.",".'"'.$_POST["txtOp1"].'"'.",".'"'.$_POST["txtOp2"].'"'.",".'"'.$_POST["txtOp3"].'"'.",".'"'.$_POST["txtOp4"].'"'.",".$_POST["selR"].",1,".$_POST["selD"].",0,0,0,2);");

...







When I check the corresponding value into the data base it is empty Unsure. Can you help me?

Thanks
mycs


antonitus
Novice

Sep 22, 2004, 1:29 PM

Post #16 of 21 (6519 views)
Shortcut
Re: [mycs] Updating Information to MySQL [In reply to] Can't Post

Ok. It's getting a little confusing. Where is this row empty during the insert process or the update process, as you said you had no problems with the insert statement or am I wrong?

Also why do you have to insert these 'values' into the database? This won't work because you do not need to insert these values into this particular textarea for it to work. I think the way that you are creating this is complex. It doesn't have to be complex, it's a simple procedure and all you need is to call the textarea tag. Ideally you really need two database fields, the first the 'id' of course and the other the textarea field which you can just call 'textarea', that's all. I don't really understand why you have to insert this additional data into your database unless there is something else going on which it looks to me like there is. To really cut a long story short you need to have these statements for:

1. INSERT:
$sql = "INSERT INTO tablename (ta) VALUES ('$ta')";

Notice the 'VALUES' statement, it just has to call 'ta' and nothing else.

2. UPDATE:
$sql = "UPDATE tablename SET ta='$ta' WHERE id='$id'";

Notice the WHERE id='$id' statement, this is crucial to identify the id of the row as I'm sure you know this.

I hope this makes sense, let me know otherwise.

Tony


mycs
Novice

Sep 22, 2004, 1:45 PM

Post #17 of 21 (6516 views)
Shortcut
Re: [antonitus] Updating Information to MySQL [In reply to] Can't Post

Tony, the table in the data base has all this fields, see this is for a question and his choices, so i have the question wich is the htmlarea and the choices are simple textareas. That's why you see all those values.

According to what you wrote i have to put this "INSERT INTO tablename (ta) VALUES ('$ta')"; ?

My question is where $ta is set, because i don't get how this is going to work if i don't set the $ta variable. I don't really get it Frown

Thanks

Marlyn


antonitus
Novice

Sep 22, 2004, 3:50 PM

Post #18 of 21 (6507 views)
Shortcut
Re: [mycs] Updating Information to MySQL [In reply to] Can't Post

Hi mycs,

I see what you mean.

Try this, I think you need to add some more code in the form tag like this (in red):


Code
 <form name="form" method="POST" action="<?= $_SERVER["PHP_SELF"]; ?>" onSubmit="return validateform(this);" id="edit" name="edit">



Also as a test remove this line (onSubmit="return validateform(this);") above and try it as sometimes javascript code messes the functionality of your page

The reason I say this that the HTMLArea software uses this 'edit' name id in it's code. You need to have this bit of code in your htmlArea page: (Maybe you haven't inlcuded the necessary HTMLArea code in your page).


Code
 <script type="text/javascript"> 
function mySubmit() {
// document.edit.save.value = "yes";
document.edit.onsubmit(); // workaround browser bugs.
document.edit.submit();
};
</script>



Let me know if this is ok.

Tony


mycs
Novice

Sep 22, 2004, 4:37 PM

Post #19 of 21 (6505 views)
Shortcut
Re: [antonitus] Updating Information to MySQL [In reply to] Can't Post

Ok, what you suggest works but wihtout onSubmit="return validateform(this);" so do you know how am i supposed to check the user input all the data? i mean how a validate the form?

I check into the data base an the textarea is saved with the html tags.

THANKS A LOT i've been dealing with this for 3 days.
mycs


antonitus
Novice

Sep 23, 2004, 6:05 AM

Post #20 of 21 (6485 views)
Shortcut
Re: [mycs] Updating Information to MySQL [In reply to] Can't Post

I'm glad to see that everything is working fine as the 'onSubmit' code is already being used by HTMLArea code, that's why you had these problems.

As far as finding some kind of javascript code to validate your script is beyond the scope of this software. You need to avoid using 'onSubmit' so maybe you can code the validate function in PHP. Do searches on the internet for the code and amalgamate it in your owm PHP script.

Good Luck!

Tony


mycs
Novice

Sep 23, 2004, 8:14 AM

Post #21 of 21 (6478 views)
Shortcut
Re: [antonitus] Updating Information to MySQL [In reply to] Can't Post

Hi Tony,

I read that if i comment some code i can use my javascript to validate the form but i can't find the correct way to do it this way.

This is the piece of code in the htmlarea.js:

if (textarea.form) {
// we have a form, on submit get the HTMLArea content and
// update original textarea.
textarea.form.onsubmit = function() {
editor._textArea.value = editor.getHTML();
};
}

Do you have an idea about commenting this and check the form with my javascript?

Thanks

mycs

 
 
 


Search for (options)