DB Insert User: Put plus (+) symbol instead of space. MySQL/PHP
Is there a way to find to put a plus symbol instead of a space.
For Example:
if (isset($_POST['user'])&&isset($_POST['server'])) {
//Prevent SQL injections
$user = mysql_real_escape_string($_POST['user']);
$server = mysql_real_escape_string($_POST['server']);
//Check to see if email exists
$sql = mysql_query("SELECT user, server FROM users WHERE user = '|$user' AND server = '$server'");
if (mysql_num_rows($sql)>0) {
die ("Name already in use with this server combination.");
}else {
开发者_开发技巧
//query the data
$query = "INSERT users SET user = '|$user', server = '$server'";
mysql_query($query);
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=data-insert.php?success=1&server='.$server.'&user='.$user.'">';
}
}
I want $user to have a + symbol instead of space if they entered one. Possible or no?
Thanks for your help.
You can do a simple string replacement at INSERT
time:
$query = "INSERT users SET user = REPLACE('|$user', ' ', '+'), server = '$server'";
Replace it:
$user = str_replace(' ','+',$user);
Check its existence:
if(strpos($user,' ') !== FALSE)
+
, in a URL, means a space. If you want to pass a +
symbol though a URI then you have to encode it (which you should be doing to any data you insert into a URI anyway).
精彩评论