Jump to content

Archived

This topic is now archived and is closed to further replies.

jbille

replacing special characters in php form

Recommended Posts

I was wondering how I could replace a period(.) and a dash(-) when passing them through a form to mysql.

Share this post


Link to post
Share on other sites
What character besides "" can I replace it with so I can return it back to original form when outputting it.

Share this post


Link to post
Share on other sites
Are you trying to replace them because your getting errors when you pass data containing those characters?  if so, check out addslashes() and stripslashes() in the [url=http://www.php.net]PHP MANUAL[/url]

Share this post


Link to post
Share on other sites
Use this on all varables that select from the database.

$example=mysql_real_escape_string($example));

[code]
<?php
// Connect
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
  OR die(mysql_error());

// Query
$query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",
          mysql_real_escape_string($user),
          mysql_real_escape_string($password));
?>
[/code]

Share this post


Link to post
Share on other sites
you can replace it with anything unique like

[code]
<?php
$stringtostore=str_replace(".","perxx",$string);
?>[/code]

and then when you get it back out, replace it back with-

[code]<?php
$gotstring=str_replace("perxx",".",$storedstring);
?>[/code]

Share this post


Link to post
Share on other sites
I am trying to let the user enter 123-456 in the form, and I want to load that number in a database.  However when I try this it just loads 123 in mysql and it stops at the -.  The same goes for 2.50, this puts 2 in the database.  And when I try to use $number=str_replace("-","000000", $number); it puts a false number into mysql.  I am using 000000 because $number is an INT(30).

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.