Forums

Having SQL Problems

Syntax: c, conn = connection() c.execute("SELECT * FROM Posts WHERE SUBSTRING_INDEX(name," ",1)=%s",(sin,)) ptitles = [item1[0] for item1 in c.fetchall()]

Error: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1)='Aakash'' at line 1")

But everything works good in mysql console when I try. I done the commit() statements. Need help VERY FAST

You have unescaped double quotes inside of a string. Python is (I think), concatenating the strings together, so the query you're actually running is this:

c.execute("SELECT * FROM Posts WHERE SUBSTRING_INDEX(name,,1)=%s",(sin,))

and that's not valid SQL syntax.