dqs86517 2016-10-15 15:42
浏览 63

PHP从选项中发布十六进制值,并以字符串格式存储到mysql

I need to store a hexadecimal value (values posted from my <options>) to my mysql database without transforming it (stay as is in string form) so that I can compare that value to my select options in string form. I've tried a lot of things, like base_convert(), (string), hex2bin(), but unfortunately. I don't know how to do this.

enter image description here

The image shows the stored value.

This is what I have done so far.

login.php:

$q = mysqli_query($con, "select * from users where email = '$email' and password = '$password'");
if (mysqli_num_rows($q) == 0)
{
$response['message'] = "Account not found.";
}
else
{
$_SESSION['user_currency'] = (string)$f['user_currency'];
}

dasboard.php:

<form id="form_setting_currency">
<select name="select_currency_symbol" class="form-control">
 <option value="&#x24;" <?php echo $_SESSION['user_currency'] == "&#x24;" ? "selected" : ""; ?> >&#x24; Dollar</option>
 <option value="&#xa2;" <?php echo $_SESSION['user_currency'] == "&#xa2;" ? "selected" : ""; ?> >&#xa2; Cent</option>
 <option value="&#xa3;" <?php echo $_SESSION['user_currency'] == "&#xa3;" ? "selected" : ""; ?> >&#xa3; Pound Sterling</option>
<option value="&#xa5;" <?php echo $_SESSION['user_currency'] == "&#xa5;" ? "selected" : ""; ?> >&#xa5; Yen</option>
</select>
</form>

SUBMIT_change_currency.php

<?php
include "includes/connection.php";
require_once("includes/encryption.class.php");

$response['success'] = false;
$response['message'] = "An error has occurred.";

if(isset($_POST['select_currency_symbol']) &&     trim($_POST['select_currency_symbol']) != "")
{

$currencyIcon = mysqli_real_escape_string($con,$_POST['select_currency_symbol']);
// $currencyIcon = mysqli_real_escape_string($con,hex2bin($_POST['select_currency_symbol']));
// $currencyIcon = mysqli_real_escape_string($con,(string)$_POST['select_currency_symbol']);

$query ="UPDATE users SET user_currency = '$currencyIcon' WHERE user_id =   $_SESSION[user_id]";
mysqli_query($con,$query);

if(mysqli_affected_rows($con)>0)
{
    $response['success'] = true;
    $response['message'] = "Successfully changed currency symbol.";
    $_SESSION['user_currency'] = (string)$currencyIcon;
}
else
{
    $response['message'] = "You have not made changes.";
}
}
die(json_encode($response));
?>      `
  • 写回答

1条回答 默认 最新

  • dongmu1951 2016-10-15 15:48
    关注

    You need to print it with htmlspecialchars() in the value, so it becomes & amp;#x24

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?