editing rows / submitting more than 255 characters of text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

editing rows / submitting more than 255 characters of text

Post by Leao »

Hi, can you help me with these 2 problems?

1) What PHP code do I need to edit a row in a MySQL database? For example I understand that you use INSERT INTO to add another row. Can you explain in detail what I would need to do?

2) Also, when using a form to submit text to a MySQL database so far the maximum length the database will accept appears to be 255 characters. How can I get around this?

Many, many thanks,

Leao
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

This is database related and should therefore go in the databases forum.
an you explain in detail what I would need to do?
No I'm too lazy but the MySQL manual can: http://dev.mysql.com/doc/refman/5.0/en/update.html
maximum length the database will accept appears to be 255 characters. How can I get around this?
VARCHAR max len is 255. TEXT and friends are much greater http://dev.mysql.com/doc/refman/5.0/en/ ... ments.html the mysql manual isn't particularly user friendly in that area, lets just say use SMALLTEXT and you can store up to 64kb, MEDIUMTEXT is bigger etc.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: editing rows / submitting more than 255 characters of te

Post by feyd »

Leao wrote:Hi, can you help me with these 2 problems?
Two problems, one quite broad, one simple. I'll do my best to illuminate.
Leao wrote:1) What PHP code do I need to edit a row in a MySQL database?
  • mysql_connect()
  • mysql_select_db()
  • either an UPDATE, INSERT, REPLACE or DELETE query.
  • mysql_query()
  • sprinkling in some mysql_error()'s is good too.
Leao wrote:Can you explain in detail what I would need to do?
Sorry, I try to hand-hold as little as possible. All I can suggest is some research here, on php.net and Google.
Leao wrote:2) Also, when using a form to submit text to a MySQL database so far the maximum length the database will accept appears to be 255 characters. How can I get around this?
Both CHAR and VARCHAR types have a maximum of 255. There are a few other TEXT based data types such as TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. If memory serves, the limits are 255 bytes, 64K, 16M and 4GB respectively.
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

Post by Leao »

Thanks.

I tried to use the REPLACE query but it seemed to just add more rows rather than replacing the existing ones wiith new data.

What am I doing wrong??

Cheers – Leao
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If REPLACE doesn't find a record that matches the given constraints it inserts the data.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Use UPDATE to edit an existing row like I said.
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

Post by Leao »

Hi, thanks a lot for your help : ) I've got the UPDATE function working now but it doesn't seem to like text featuring speech marks. I'm using a textarea to UPDATE my mysql. When I submit text featuring speech marks it returns the following 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 'm testing'' at line 1'

Thanks again,

Leao
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

Post by Leao »

Thanks again.
Post Reply