jbille Posted October 18, 2006 Share Posted October 18, 2006 I was wondering how I could replace a period(.) and a dash(-) when passing them through a form to mysql. Quote Link to comment Share on other sites More sharing options...
Caesar Posted October 18, 2006 Share Posted October 18, 2006 [code]<?phpstr_replace(".","",$string);?>[/code] Quote Link to comment Share on other sites More sharing options...
jbille Posted October 18, 2006 Author Share Posted October 18, 2006 What character besides "" can I replace it with so I can return it back to original form when outputting it. Quote Link to comment Share on other sites More sharing options...
sanfly Posted October 18, 2006 Share Posted October 18, 2006 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] Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 18, 2006 Share Posted October 18, 2006 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] Quote Link to comment Share on other sites More sharing options...
slancasterfreak Posted October 18, 2006 Share Posted October 18, 2006 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] Quote Link to comment Share on other sites More sharing options...
jbille Posted October 19, 2006 Author Share Posted October 19, 2006 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). Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 19, 2006 Share Posted October 19, 2006 use varchar(30) then try ok. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.