Forum Moderators: coopster

Message Too Old, No Replies

A shrinking field

Losing characters in varchar

         

henry0

10:55 am on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I do not know if I will make sense, however here you are:
Scenery: My own CMS –proven records, works fine-
PHP MySQL, two main files A) new_content.php that includes my editor with many editor instances and a few fields that do not need editor intervention and that are simple form edit and sustained by on board CSS and B) submit.php its title says all.

Only one DB field is affected by the problem
“biz_name” varchar 50, keep in mind the number cause it matters.
Since I am testing a retesting the new site I edit and submit many times
Obviously biz_name does not need any edit BUT
Any times I edit any other field (but not biz_name) and click on submit biz_name got automatically one white space added in the DB in front of BizName and if my biz_name is say 47 long after 4 submits I will miss the last letter
(50-4=46) and there goes my 47th letter out of BizName value initially 47 letters long, another submit and I will lose another one.
I looked at it through PHPmyAdmin and found that the title position moved with each submit to the right of the PHPmyAdmind field
For ex:
Before: BizName
After a few hits....... BizNa (used dots, I cannot create white space on the forum)
What’s happening here?
Sorry for the long post

Regards

Henry

lucidpc

11:04 am on Apr 8, 2005 (gmt 0)



please post your update query

henry0

12:06 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I lucidpc welcome on webmasterworld
<TEXTAREA COLS=80 ROWS=1 NAME="business_name" WRAP=VIRTUAL>
<? print $s[business_name];?></TEXTAREA>

and then it goes here:

$business_name =$_POST['business_name'];

$sql= "select id from group_1 ";
$result = mysql_query($sql,$conn);
while ($new_content=mysql_fetch_array($result) )
{
$id= $new_content[id];
}
$new_content=$id;
if ($new_content) { // It's an update
$sql = "update group_1
set new_content_text ='$new_content_text',
business_name ='$business_name',
etc... other fields
modified = '$time'
where id = $new_content";

so with any new updates a same existing biz_name(if not modified) is sent but there is no reason for it to gain a larger value with every hit

I used the same formula many times and never had that glitch

henry0

2:47 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Even more strange
I found that three more fields that are submited as the other field that causes problem are not affected
however I compared and cannot find anything that looks different

StupidScript

4:28 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The other fields that work: Are they also TEXTAREAs?

Check the value of business_name when it is received:

$business_name =$_POST['business_name'];

echo str_replace(" ","-",$business_name)."<br />\n";

exit;

(Since this is a test, I used

exit
to stop the routine before it ran the update query.)

Replacing any spaces with dashes before echoing the variable's value should let you see what's happening with the extra spaces.

For a quick fix, use this in your upddate query:

business_name ='ltrim($business_name)',

ltrim()
will remove any whitespace at the start of the string, so they won't keep adding up.

henry0

5:01 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



StupidScript thanks,
Well, str-replace just echo what it is supposed to.

and
business_name ='ltrim($business_name)',
does not work it goes in the DB as: "ltrim (mybiz)"
exactly as it appears between the " "
however (mybiz) is the correct name to pass by business_name

and yes the other non affected fields are TEXTAREA
exactly CC of this other textarea field that cause problem, although the last textarea do work fine!

StupidScript

5:17 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oops. Sorry. Try this:

$trim_name=ltrim($business_name);

then

business_name ='$trim_name',

Are you thinking that the space is being added by mySQL?

henry0

5:43 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks
I should have seen that one!

ready for the bad news:
ltrim does not carry the expected effect
I stil get my input moving forward in the DB

FYI
it is not affected by other input since that one sits on the very top of the logic process

willybfriendly

6:14 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<TEXTAREA COLS=80 ROWS=1 NAME="business_name" WRAP=VIRTUAL>
<? print $s[business_name];?></TEXTAREA>

Don't know how you may be handling the data before you store it, but the problem may be there. You will need to undo any changes you made prior to stroing the data into DB before you display it again.

Try replacing the above with <? print trim($s[business_name]);?>

WBF

henry0

6:38 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



WillybFriendly,
StupidScript was starting to get the correct idea

but using trim DID IT :)

Thanks

best regards

Henry