Home  >  Article  >  Backend Development  >  How to deal with this problem of single and double quotation marks?

How to deal with this problem of single and double quotation marks?

WBOY
WBOYOriginal
2016-08-04 09:20:061158browse

<code>$current_account_url='<a class="mini-button" iconcls="icon-edit" 
onclick="printabc('html/达能益力贸易(深圳)有限公司-[101]广东
2016-04-01-2016-04-30对账单.html')">查看/打印1</a>'; 
</code>

How can I insert it into the field in the table? I tried it for a long time but couldn't do anything. . Thank you

<code>$sql_url="update tools_current_account set current_account_url='$current_account_url' where Current_unit='$current_unit' and status=1 AND starttime='$starttime' and endtime='$endtime'";</code>

Reply content:

<code>$current_account_url='<a class="mini-button" iconcls="icon-edit" 
onclick="printabc('html/达能益力贸易(深圳)有限公司-[101]广东
2016-04-01-2016-04-30对账单.html')">查看/打印1</a>'; 
</code>

How can I insert it into the field in the table? I tried it for a long time but couldn't do anything. . Thank you

<code>$sql_url="update tools_current_account set current_account_url='$current_account_url' where Current_unit='$current_unit' and status=1 AND starttime='$starttime' and endtime='$endtime'";</code>

I see there is a problem with your SQL! Can you insert the value of the variable into the database if you quote it with single quotes?

Escape with '.

There is no problem with your syntax, but there is a problem when you assign the value of $current_account_url. The single and double quotes are used incorrectly
How to deal with this problem of single and double quotation marks?
It is recommended that you use delimiters

How to deal with this problem of single and double quotation marks?

Use php base64_encode before inserting and then insert
or use mysql hex() before inserting to avoid these problems

When inserting into the database, you can use backslash escaping or base64 encoding.
But I think your problem seems to be that you don’t know how to deal with the nesting of single and double quotes in $current_account_url. As a result, the line $current_account_url keeps getting errors.
Nested methods can also use escaping, or as follows

<code>$current_account_url='<a class="mini-button" iconcls="icon-edit" 
onclick="printabc(' . "'" . "html/达能益力贸易(深圳)有限公司-[101]广东
2016-04-01-2016-04-30对账单.html" . "'" . ')">查看/打印1</a>'; </code>

Thank you everyone, thank you @yangxiangming for the reminder. After escaping with addslashes(), you can insert and read normally

Don’t you get an error when running?
$current_account_url="View/Print 1 ";
Try this.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn