PHP & text fields

Punctuation Turn Into Question Marks

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1022 Views - Last Post: 17 June 2009 - 05:59 PM Rate Topic: -----

#1 LadyYepperz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-June 09

PHP & text fields

Posted 15 June 2009 - 07:44 PM

My form written in PHP & XHTML - the periods are turning into question marks! but not all of them, only the ones in pairs or more.

Example: "etc..." becomes "etc???"

Ive tried replacing both the text periods (.) and question marks (?) with ASCII code. Its not working!! Nothing is working!!

Im at my wits end and Im about to SCREAMMMM!!

If you know why this is happening please help, thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: PHP & text fields

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5310
  • View blog
  • Posts: 27,210
  • Joined: 10-May 07

Re: PHP & text fields

Posted 15 June 2009 - 07:45 PM

View PostLadyYepperz, on 15 Jun, 2009 - 08:44 PM, said:

If you know why this is happening please help, thank you.

Any chance we could see the code that handles the $_POST values?
Was This Post Helpful? 0
  • +
  • -

#3 LadyYepperz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-June 09

Re: PHP & text fields

Posted 15 June 2009 - 07:56 PM

function replace_chars($var){
$illegal=array("!", "\"", "$", "%", "(", ")", "*", "+", "'", "=", "<", ">", "{", "}", "|", "~", ",");
$replace=array("& #33;", "& #34;", "& #36;", "& #37;", "& #40;", "& #41;", "& #42;", "& #43;", "& #39;", "& #61;", "& #60;", "& #62;", "& #123;", "& #125;", "& #124;", "& #126;", "& #44;");
 $var=str_replace($illegal, $replace, "$var");
 return $var;
}

$title=replace_chars(stripcslashes($_POST[title]));
$piece=nl2br(replace_chars(stripcslashes($_POST[piece])));


(ok.. the ASCII isnt printing properly. so i added extra spaces.)
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5310
  • View blog
  • Posts: 27,210
  • Joined: 10-May 07

Re: PHP & text fields

Posted 15 June 2009 - 08:00 PM

Which value contains the question marks? Your $_POST array, or $title (or $piece) ?
Was This Post Helpful? 0
  • +
  • -

#5 LadyYepperz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-June 09

Re: PHP & text fields

Posted 15 June 2009 - 08:08 PM

$title & $piece

these are the variables thats being inserted into the db...

but get this... this problem is happening during the insertion. both $title and $piece are previewed before inserting and im not having the problem until it goes into the db.

This post has been edited by LadyYepperz: 15 June 2009 - 08:11 PM

Was This Post Helpful? 0
  • +
  • -

#6 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: PHP & text fields

Posted 15 June 2009 - 09:04 PM

i think you you are missing something.
check this: you are missing single marks
$title=replace_chars(stripcslashes($_POST['title']));
$piece=nl2br(replace_chars(stripcslashes($_POST['piece'])));

Was This Post Helpful? 0
  • +
  • -

#7 LadyYepperz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-June 09

Re: PHP & text fields

Posted 15 June 2009 - 09:30 PM

ok.. i will try that and report back tomorrow..
its very late here and my brain is fried. thank you guys!
Was This Post Helpful? 0
  • +
  • -

#8 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: PHP & text fields

Posted 16 June 2009 - 03:29 AM

View Postnoorahmad, on 15 Jun, 2009 - 08:04 PM, said:

i think you you are missing something.
check this: you are missing single marks
$title=replace_chars(stripcslashes($_POST['title']));
$piece=nl2br(replace_chars(stripcslashes($_POST['piece'])));

That's not the problem, would only throw a notice about undefined constant depending on the error_reporting level.

How are you entering data? Are you copying it from an application such as word?

The reason I ask is because in Word, "..." is automatically translated to some retarded single character, which may not be recognised by MySQL (I haven't tested it). I would suggest that you get the character value of each char in the string (using ord()) and see if they differ from "normal" periods.
Was This Post Helpful? 0
  • +
  • -

#9 LadyYepperz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-June 09

Re: PHP & text fields

Posted 17 June 2009 - 10:29 AM

@ Mage

That may very well be it!! I copied and pasted from a .txt file to test my scripts. The double quotes (") were turning into question marks too until i replaced them all in the .txt file.

Shoot!! if that is the case how do i auto correct the problem??? My site is a place for writers to post original stories. Most WILL copy & paste from other applications!!

Please any suggestions??!!
Was This Post Helpful? 0
  • +
  • -

#10 TTechGuy  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 63
  • Joined: 24-April 09

Re: PHP & text fields

Posted 17 June 2009 - 10:39 AM

Ok, I may be misunderstanding, but shouldn't you be adding slashes for what's being put into the database instead of stripping them?
Was This Post Helpful? 0
  • +
  • -

#11 LadyYepperz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-June 09

Re: PHP & text fields

Posted 17 June 2009 - 10:53 AM

Ok.. i thought about leaving the slashes. But as this text box allows for very large amounts of text i thought it would be safer to code everything that may be objectionable or lead to a db attack before inserting into the db.

My Form fields:
<input type='text' name='title' value='".htmlentities($title,ENT_QUOTES)."' size='45' maxlength='40'  tabindex=1/>

<textarea rows='30' cols='100%' name='piece' value='' tabindex=4>$piece</textarea>



if i leave the slashes in place, the mysql db may still not recognize these goofy characters and still print question marks (?).
Was This Post Helpful? 0
  • +
  • -

#12 TTechGuy  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 63
  • Joined: 24-April 09

Re: PHP & text fields

Posted 17 June 2009 - 11:07 AM

I meant literally add slashes to the variable to prevent injection.

$title = addslashes($title);
$piece = addslashes($piece);



Then strip them back out for display when reading the database. I'm not sure that's the exact answer, but it seems like the way it would work.
Was This Post Helpful? 0
  • +
  • -

#13 LadyYepperz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-June 09

Re: PHP & text fields

Posted 17 June 2009 - 11:32 AM

tried that... didnt work... mysql doesnt know what to do with the characters. it would seem they are ASCII high characters. the period (.) for instance is #226; - a normal period (.) is #46;.

there has to be a solution to this problem ... i cant be the only one to ever experience this.

=======================

off topic... maybe this thread needs to be moved to the MYSQL section of the forum.

This post has been edited by LadyYepperz: 17 June 2009 - 11:42 AM

Was This Post Helpful? 0
  • +
  • -

#14 LadyYepperz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-June 09

Re: PHP & text fields

Posted 17 June 2009 - 12:07 PM

in my MYSQL DB i selected ascii_general for the collation. maybe the solution is as easy as changing it to latin.

problem is... there are 19 freaking choices!! which one??

or no choice at all... hmmmm

This post has been edited by LadyYepperz: 17 June 2009 - 12:08 PM

Was This Post Helpful? 0
  • +
  • -

#15 LadyYepperz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-June 09

Re: PHP & text fields

Posted 17 June 2009 - 12:29 PM

:D YAY ITS FIXED!! WHOOOO!! :D

Thank you to everyone who helped me figure this out!!
Yaaaaaaaay!!! I was right... by changing the collation to latin1, it sorted itself out!!

Happy Happy Joy Joy!!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2