ds1379551 2014-09-17 04:16
浏览 63
已采纳

如何使用带有MySQL数据库的HTML表单搜索带加号(+)的字符串? [关闭]

I have a very simple form that allows the user to search for a company name. One of the company names is "A+ Service". How can I build the form to encode the plus (+) sign prior to submitting the form, to allow for the user to input "A+" and find this company?

The form is submitting via POST.

A bit of background to help explain. Here's the code for the form itself:

<form action="/search_customer.php" method="post" enctype="multipart/form-data"
      id="search_form" onsubmit="return validateSearch(document.search_form);">
Search Customers:
<input id="search_text1" name="global_search_text" type="text" value="">
<input type="submit" name="global_search" id="global_search" value="Go">
</form>

When we submit this form with "a+" as the search term, the resulting SQL is:

SELECT * FROM tbl_customer
WHERE ( cus_fname LIKE '%a%' OR cus_lname LIKE '%a%');

My understanding is that we'll need to encode the value of the search string prior to submitting the form, but we're not clear on how to do this.

  • 写回答

2条回答 默认 最新

  • dongzhuange2625 2014-09-17 04:31
    关注

    I think your problem is related to the + being translated as a space.

    If you are sending the data using javascript, you could encodeURIComponent the value at first.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

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