Forum Moderators: coopster

Message Too Old, No Replies

I can't edit <textarea >

After adding info, editing function wont save new data

         

brokenbricks

9:43 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



To summarize, I hired someone to do php/mysql for one of my sites since I know VERY little about doing it myself....They did not complete the job, leaving me out of money, out of time, and out of patience trying to fix everything on my own.

When users sign up to the site, they fill in a form with various info, this info is saved to the DB fine... There is an option for the user to edit their info, edit_widget.php
When I test it out, I am able to edit the first 10 fields of the form, submit the changes, and they save correctly.

<input name="widget" type="text" size="70" maxlength="500" value="<? echo $row['widget']?>" /> is an example that works properly...

But if I change either of the last 2 fields which are <textarea>'s It causes some type of error and no info saves, meaning users cannot edit any of their information, which is crucial for this site.

The text areas also display fine in my editing program, but in IE there is some white space before them, for unknown reasons..and in FireFox the textarea has no whitespace but it exceeds the pagecell a little bit...leading me to believe this is where the problem is...

<textarea name="story" cols="70" rows="4" wrap="virtual"> <? echo $row['story'];?></textarea> is an example of the text area's...

I'm aware that upon clicking submit, another php file runs and transfers that info into the db, I don't think that file is the problem since If I edit the first 10 fields it works fine...

So what could be a problem with this that causes an error and no data to be edited/saved? Is it on page? Is it within the database?

Perhaps I'm overlooking something very simple, but I am a total newbie php/mysql.

Any help is greatly appreciated..

lobo235

12:51 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



It could be that magic_quotes_gpc is turned off so the data in the textareas might break the SQL query that updates the info in the database. Try entering something into the textareas that does not have any single quotes. For example, you could try changing the data to "hello". If that works then more than likely your problem can be solved by using the addslashes() function to make the data going into the database safe to insert/update. Hope this helps.

brokenbricks

1:58 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



I changed certain fields to 'hello' and to my shock it updated!

How would I go about applying that function so regular text and whatever the user is gonna enter will also update?

Thanks so much

**update**
I tried this on one and it worked, I tried it on another and it doesn't update. None of the fields or text areas update when I change them ..

I can post the code that I received here, but I don't understand why it would work for one but not the other...

lobo235

2:13 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



Well, basically, you need to apply the addslashes() function to any data that is entered in forms. For example, if your form uses the "post" method then you would do this to each variable:

$firstname = addslashes( $_POST['firstname'] );
$lastname = addslashes( $_POST['lastname'] );

And so on. Now in your MySQL query you can use the variables $firstname and $lastname because they should be safe. This works in most cases but to be absolutely safe you should use the quote_smart() function example on the php.net site here [php.net ]

For the fields that still didn't work when you changed them to "hello" there is something else wrong with them. My advice is to find someone who knows PHP well and hire them to finish the job.

brokenbricks

2:21 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



Thanks for your input..

Can't say I've had good experience hiring people since this happend.

I just tried to enter some new entries and test it, and for some reason the editing works now...so It can't be the code...

It basically works on every user but not the #1 in the database, I can't figure out why...

Thanks again for your help.

brokenbricks

5:00 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



I've also discovered another area where there is this problem, a page where users enter text into a little blog entry basically does the same , if I type hello or one word in there it registers , if i write a paragraph sometimes it shows up but it usually does not...

lobo235

6:32 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



Sounds like the same problem. The data needs to be run through the mysql_real_escape_string() function first to make it safe for a database insert.

brokenbricks

8:31 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



Would this be the best thing to do, or would turning magic_quotes_gpc on fix it also?

Thanks

lobo235

8:54 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



magic_quotes_gpc will most likely fix this issue but to be completely safe you should use mysql_real_escape_string()