If value true but null not work
<p>I made program is input number and delete data in mysql. but run program error then report <code>sql1</code> Syntax Error\i change true</p>

<pre><code>#!/usr/bin/python

import mysql.connector

conn = mysql.connector.connect(host="",user="",passwd="",db="")
cursor = conn.cursor()

try:
        num = int(input("InputNumber 1-10 : "))
        if num &lt;= 10:
                if num == null: //if null print false
                        sql1 = "SELECT user1 FROM dt WHERE user1 = '%d' " %(num)
                        cursor.execute(sql1)
                        data = cursor.fetchall()
                print(data[0])
                sqlde = "DELETE FROM dt WHERE user1 = '%d' " %(num)
                cursor.execute(sqlde, (num))
                print "DELETE SUCESS"
                conn.commit()
        else:
                print "Data Empty"
except:
        conn.rollback()

conn.close()
</code></pre>

<p>num =   int(input("InputNumber: ")<code>)</code>  &lt;- don't forguet to close it</p>

<p>I'm not sure about the <code>%i</code>, I always see using <code>%d</code> for Integer and <code>%s</code> to strings</p>

<p>But, you also have one problem into your query, <a href="https://en.wikipedia.org/wiki/SQL_injection" rel="nofollow">SQL Injection</a></p>

<p>So to avoid this, try something like this</p>

<pre><code>sql1 = "DELETE FROM dt WHERE user1 = ?"
                try:
                        cursor.execute(sql1, (num))
                        print "DELETE SUCECC"
                        conn.commit()
                except:
                        conn.rollback()
                        print "ERROR DELETE"
</code></pre>

<p>you can check about <a href="http://www.sqlite.org/c3ref/bind_blob.html" rel="nofollow">question mark here</a> or <a href="https://en.wikipedia.org/wiki/Prepared_statement#Parameterized_statements" rel="nofollow">here</a> and understand why you should bind your values</p>

python mysql