doupuzhimuhan9216 2019-06-08 05:16
浏览 1007

无法将特殊字符插入MySQL表

I need to update one string value which contains /n into mysql table but after update that string value creates new line.

I am using some code which is given below.

require_once 'include/dbconfig.php';
$tracking_id='108597711876';
$payment_mode='Debit Card';
$card_name='Maestro Debit Card';
$status_message='SUCCESS';
$bank_ref_no='327446';
$str="tracking_id : ".$tracking_id."\
payment_mode : ".$payment_mode."\
card_name : ".$card_name."\
status_message : ".$status_message."\
bank_ref_no : ".$bank_ref_no;
$qry ="UPDATE cb_all_state set comment='".$str."' WHERE id=1";
$sql=mysqli_query($connect,$qry);

I need to entry the string value as below format directly.

tracking_id : 108597711876
payment_mode : Debit Card
card_name : Maestro Debit Card
status_message : SUCCESS
bank_ref_no : 327446

But after update I am getting the following data inside the column.

tracking_id : 108597711876
payment_mode : Debit Card
card_name : Maestro Debit Card
status_message : SUCCESS
bank_ref_no : 327446

Here actually I need to entry the string value with /n but it creates new line after update.

  • 写回答

1条回答 默认 最新

  • dtpngq3378499 2019-06-08 09:31
    关注

    mysqli_real_escape_string($str) should assist you here as it will handle escaping special characters like new lines. In your code this should be:

    $str="tracking_id : ".$tracking_id."
    payment_mode : ".$payment_mode.
      "
    card_name : ".$card_name."
    status_message : ".$status_message.
      "
    bank_ref_no : ".$bank_ref_no;
    $qry ="UPDATE cb_all_state set comment='". mysqli_real_escape_string($str). "' WHERE id=1";
    $sql=mysqli_query($connect,$qry);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?