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 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型