PHP select value not saving to MySQL -
cannot figure out why below save fine on local test server, not on hosted. dollar sign value save on hosted. save fine on local.
for both have "enum('$', '€', '¥', '£')
" type utf8_unicode_ci collation.
<select name="user_currency" id="user_currency"> <option value="$" <?php echo ($user_currency == '$'?'selected="selected"':'');?>>$ - dollar</option> <option value="€" <?php echo ($user_currency == '€'?'selected="selected"':'');?>>€ - euro</option> <option value="¥" <?php echo ($user_currency == '¥'?'selected="selected"':'');?>>¥ - yen</option> <option value="£" <?php echo ($user_currency == '£'?'selected="selected"':'');?>>£ - pound</option> </select>
the query:
$query = "update users set user_currency = ".$db->prep($_post['user_currency'])." us.user_id = '{$user_id}'";
the prep function
function prep($value,$strip_tags = 1){ // stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // quote if not integer if (!is_numeric($value) || $value[0] == '0') { $value = "'" . mysql_real_escape_string($value) . "'"; } if($strip_tags){ $value = db::strip_html_tags($value); }else{ $value = db::strip_html_tags($value,0); } return $value; }
any ideas?
perhaps should try changing part:
<select name="user_currency" id="user_currency"> <option value="$" <?php echo ($user_currency == '$'?'selected="selected"':'');?>>$ - dollar</option> <option value="€" <?php echo ($user_currency == '€'?'selected="selected"':'');?>>€ - euro</option> <option value="¥" <?php echo ($user_currency == '¥'?'selected="selected"':'');?>>¥ - yen</option> <option value="£" <?php echo ($user_currency == '£'?'selected="selected"':'');?>>£ - pound</option> </select>
to be:
<select name="user_currency" id="user_currency"> <option value="$" <?php echo ($user_currency == '$'?'selected="selected"':'');?>>$ - dollar</option> <option value="&euro;" <?php echo ($user_currency == '€'?'selected="selected"':'');?>>€ - euro</option> <option value="&yen;" <?php echo ($user_currency == '¥'?'selected="selected"':'');?>>¥ - yen</option> <option value="&pound;" <?php echo ($user_currency == '£'?'selected="selected"':'');?>>£ - pound</option> </select>
otherwise browser going send actual currency characters don't match stated enums. [edit] because enums html entities. might suggest switching internally using currency codes jpy, usd, etc.?
[clarification edit: iso currency codes lot easier move around, , 3rd-party apis more use them if ever decide draw upon of currency-related resources out there. why worked locally , not on external server... php version difference in entity handling if you're using of entity functions on user input. if that's case, more reason use iso currency codes.]
Comments
Post a Comment