not entering data from a form when copy, paste is used.

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
illmapu
Forum Commoner
Posts: 47
Joined: Fri Aug 22, 2003 1:48 pm

not entering data from a form when copy, paste is used.

Post by illmapu »

Hi,

I didn't know if anyone has had this problem before, but I have a text field on a form that when I type into the box, it enters the data into the database correctly, but if I copy and paste the text from a word doc, it doesn't enter the data? I know th eform works properly otherwise the data wouldn't enter when I simply type the info into the textfield.

php, mysql.

Any idea what could be wrong? I was thinking along the line of collation, but I'm not sure and I've never had the problem before.

Any help is greatly appreciated!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post your code. It's sounds like you're getting the garbage characters Word likes to drop into the clipboard when copying out of it and your script isn't designed to handle.
illmapu
Forum Commoner
Posts: 47
Joined: Fri Aug 22, 2003 1:48 pm

Post by illmapu »

Code: Select all

require('include/config.php');
if($sub){
if($title==""){print "<p class=err><br>ERROR!<br><p class=fortent> Please go back and enter your TITLE.";die;}
if($summary==""){print "<p class=err><br>ERROR!<br><p class=fortent> Please go back and enter your SUMMARY.";die;}
if($body==""){print "<p class=err><br>ERROR!<br><p class=fortent> Please go back and enter your BODY.";die;}
$title = stripslashes($title);
$summary = stripslashes($summary);
$body = stripslashes($body);
mysql_query("insert into cpsf_arts (art_rname,art_tit,art_sum,art_bod,art_dat,active) values ('$name','$title','$summary','$body','$ldat','Pending')");
echo "<h1>Your article is now pending so you can double check for any errors.</h1><br>";
}
Thanks for any help in advance!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Is there a sample of copy that doesn't work on hand? Also run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>
illmapu
Forum Commoner
Posts: 47
Joined: Fri Aug 22, 2003 1:48 pm

Post by illmapu »

Hi, the results you asked for:

PHP Version: 4.4.2
PHP OS: Linux
Error Reporting: 2039 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: On
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Loaded Extensions:
xml tokenizer standard sockets
session posix overload mysql
mcrypt mbstring gettext gd
ftp curl ctype calendar
bcmath zlib pcre apache
Zend Optimizer

I will send a copy of the text if still needed, just let me know if you still need the text and thank you for your help with this, it's the last main thing I have to complete for the project.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Can you post the form code and a paste that doesn't work and a paste that does please? I'm going to guess the text will contain one or more single quotes which will break the query. For testing purposes you may want to change your query to something similar to this:

Code: Select all

mysql_query(...) or die(mysql_error());
illmapu
Forum Commoner
Posts: 47
Joined: Fri Aug 22, 2003 1:48 pm

Post by illmapu »

ahhh, you are right. You're good!

I just tried to add the text using the single quotes as you suggested and it is the problem, as soon as I typed something using the single quotes, it didn't work. So, it didn't matter about the copy paste so much, but that what I was copying has the single quotes in it. I typed single quotes in a sentence and it didn't work like when I copied the text.

Do you know what I can do to overcome this? I used stripslashes thinking that would stop it since I know it removes the \ when an apostrophe is used, but I didn't realize the single quotes could also cause a problem.

Thanks again for your help!
illmapu
Forum Commoner
Posts: 47
Joined: Fri Aug 22, 2003 1:48 pm

Post by illmapu »

After searching through posts here, I found the answer.

I used addslashes and stripslashes, this added the slash to continue the string and it removed the \ slash for the single quotes.

Copy, pasted from doc and it worked first try without problems. :D

Thanks for your help, it led me to find the answer in here and I'm grateful as now I can get this project completed.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql_real_escape_string() is the preferred method over addslahes(). Why? It's possible to bypass addslashes(). Search through Shiflett's posts to find the proofs.
Post Reply