Jump to content

replacing special characters in php form


jbille

Recommended Posts

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]
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]
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).

Archived

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

×
×
  • Create New...

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.