[SOLVED] LONGTEXT not storing lots of text

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

[SOLVED] LONGTEXT not storing lots of text

Post by tristanlee85 »

I have this script that stores a text in a database with an attribute of LONGTEXT since I usually write a few paragraphs that need stored. I have this script on my localhost which is running MySQL4 and then I have the exact same script on my ISPconfig server with MySQL5. If I type out a lot of text and submit it to the MySQL5 database, it won't store it for some reason, but I can type an unlimited amount of text in this text box and submit the form and it'll store it to the MySQL4 database without problems.

Does anyone have any idea as to why it won't store long text in MySQL5?
Last edited by tristanlee85 on Sat Jan 27, 2007 6:08 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Packet size too small? Problem with your SQL query? It's hard to say without seeing more.
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

I don't know about being too small. It doesn't store if there is too much text. Plus, they are the exact same files on both servers and I imported the database to the MySQL5 server directly from a MySQL4 export. I'll post code tomorrow.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you can, compare the my.cnf files from both MySQL installations or possibly use

Code: Select all

show variables like '%packet%';
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Code: Select all

<?php

include 'include.php';

//Posting into database

$name=$_POST['name'];
$manager=$_POST['manager'];
$comment=$_POST['comment'];
$a=$_POST['a'];
$b=$_POST['b'];
$c=$_POST['c'];
$d=$_POST['d'];
$e=$_POST['e'];
$f=$_POST['f'];
$g=$_POST['g'];
$h=$_POST['h'];
$i=$_POST['i'];
$j=$_POST['j'];
$k=$_POST['k'];
$l=$_POST['l'];
$m=$_POST['m'];
$n=$_POST['n'];
$o=$_POST['o'];
$p=$_POST['p'];
$q=$_POST['q'];
$r=$_POST['r'];
$s=$_POST['s'];
$t=$_POST['t'];
$u=$_POST['u'];

if (empty($name)) {
	echo "The <b>Name</b> value is empty.<br><A HREF=\"javascript:history.go(-1)\">Go back</A>";
	exit;
}

if (empty($manager)) {
	echo "The <b>Manager</b> value is empty.<br><A HREF=\"javascript:history.go(-1)\">Go back</A>";
	exit;
}

if (empty($comment)) {
	echo "The <b>Comment</b> value is empty.<br><A HREF=\"javascript:history.go(-1)\">Go back</A>";
	exit;
}

$sql = mysql_query("SELECT * FROM eval_num WHERE name='$name'");
$result = mysql_fetch_array($sql);

if (mysql_num_rows($sql) != 0){
	$query = "UPDATE eval_num SET name = '$name', manager = '$manager', comment = '$comment',a = '$a',b = '$b',c = '$c',d = '$d',e = '$e',f = '$f',g = '$g',h = '$h',i = '$i',j = '$j',k = '$k',l = '$l',m = '$m',n = '$n',o = '$o',p = '$p',q = '$q',r = '$r',s = '$s',t = '$t',u = '$u' WHERE id = '{$result['id']}'";
	
} else {
	
	$query = "INSERT INTO eval_num VALUES ('','$name','$manager','$comment','$a','$b','$c','$d','$e','$f','$g','$h','$i','$j','$k','$l','$m','$n','$o','$p','$q','$r','$s','$t','$u')";
}
mysql_query($query);

if (mysql_errno() != 0) {
echo 'Error: ' . mysql_error() . '<br/>';
} 

mysql_close();

header("Location: roster.php"); 
?>
There is the code for the script that inserts the values into the database. I wrote this about a year ago when I was real new to this stuff so it isn't the best code, but it works. I'll check the my.cnf files and see how they are different.
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Here is the one on my MySQL5 server:

Code: Select all

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
And this is the one on the localhost server (the one that works correctly):

Code: Select all

# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /opt/lampp/var/mysql) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password	= your_password
port		= 3306
socket		= /opt/lampp/var/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port		= 3306
socket		= /opt/lampp/var/mysql/mysql.sock
skip-locking
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
# 
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
# log-bin deactivated by default since XAMPP 1.4.11
#log-bin=mysql-bin

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id	= 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin


# Point the following paths to different dedicated disks
#tmpdir		= /tmp/		
#log-update 	= /path-to-dedicated-directory/hostname

# Uncomment the following if you are using BDB tables
#bdb_cache_size = 4M
#bdb_max_lock = 10000

# Comment the following if you are using InnoDB tables
skip-innodb
innodb_data_home_dir = /opt/lampp/var/mysql/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/lampp/var/mysql/
innodb_log_arch_dir = /opt/lampp/var/mysql/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

And also, on the MySQL5 server, here is the output:

Code: Select all

mysql> SHOW VARIABLES LIKE '%packet%';
+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
1 row in set (0.00 sec)
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Also, my PHP versions are different. Is there any setting in a PHP config file that may limit a POST size? I'm pretty sure the file upload size is 4M, but what about arrays? Wouldn't $_POST['comment'] be an array or not?
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Ok. Well, I figured out. When I would write long comments, I ended up using apostrophes from time to time and if there was an apostrophe in the text that was being posted, that's when it would screw up. It's weird though. Both files on both server are exactly the same and on my working server, the apostrophe doesn't mess up anything. Why would it on the other server?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

magic_quotes_gpc setting difference?

(It's recommended to be off, but your code should detect it being on and correct it as needed.)
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Nice. It was set to 'On' on the working server and set to 'Off' on the one with problems. I set it to 'On' and it fixed it. Is it a bad thing that I have to turn it on to make it work right?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You need to write your code to understand how to remove its effects when on and properly escape the text afterward.

http://www.google.com/search?q=magic+quotes+are+evil
Post Reply