擅长:python、mysql、java
<p>在一个或多个参数中有回车符。因为您使用的是参数插值,所以这会打断查询字符串。但参数插值的更大问题是,这段代码容易受到SQL注入的攻击。</p>
<p>首先,请阅读:
<a href="http://initd.org/psycopg/docs/usage.html#the-problem-with-the-query-parameters" rel="nofollow noreferrer">http://initd.org/psycopg/docs/usage.html#the-problem-with-the-query-parameters</a>
那么这个:
<a href="http://initd.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries" rel="nofollow noreferrer">http://initd.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries</a>
然后,将代码重写为:</p>
<pre><code>cursor.execute('''INSERT INTO signup (id, name, email, dob, address, mobile, password) VALUES (1,%s,%s,%s,%s,%s,%s)''', (name,email,dob,address,mobile,password))
</code></pre>
<p>现在,如果您愿意,可以将“\r”传递到数据库,而且您也可以安全地避免SQL注入。</p>