Python finding a specific value in a database












0















I am creating a web application login page where the user inputs their login information and the app will take their login information, compare it to what is in the database then determine if the login is a registered user. I am starting off by doing a quick test to see if I can get the value from the database, however the problem I am having is that when I input the specific value form the user input that I want it to find, I keep getting an error stating that the value needs to be a specific parameter, row or tuple. I am using an sql server



@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
try:
connect = pypyodbc.connect('Driver={SQL server};Server=localhost;Database=capstone;uid=;pwd=')
cursor = connect.cursor()
_username = str(request.form['username'])
cursor.execute("SELECT * FROM login WHERE username= (%s)", _username)
dataUser = cursor.fetchone()[1]
return(dataUser)
except Exception as e:
return (str(e))









share|improve this question


















  • 1





    You are testing with an SQL wildcard in the where condition. Use ? as a parameter marker instead of %s.

    – Benjámin Budai
    Nov 22 '18 at 22:48











  • I have tried with ? and it still wouldn't work

    – Abbadon771
    Nov 23 '18 at 7:24






  • 1





    Are you sure _username is not None?

    – Benjámin Budai
    Nov 23 '18 at 21:24
















0















I am creating a web application login page where the user inputs their login information and the app will take their login information, compare it to what is in the database then determine if the login is a registered user. I am starting off by doing a quick test to see if I can get the value from the database, however the problem I am having is that when I input the specific value form the user input that I want it to find, I keep getting an error stating that the value needs to be a specific parameter, row or tuple. I am using an sql server



@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
try:
connect = pypyodbc.connect('Driver={SQL server};Server=localhost;Database=capstone;uid=;pwd=')
cursor = connect.cursor()
_username = str(request.form['username'])
cursor.execute("SELECT * FROM login WHERE username= (%s)", _username)
dataUser = cursor.fetchone()[1]
return(dataUser)
except Exception as e:
return (str(e))









share|improve this question


















  • 1





    You are testing with an SQL wildcard in the where condition. Use ? as a parameter marker instead of %s.

    – Benjámin Budai
    Nov 22 '18 at 22:48











  • I have tried with ? and it still wouldn't work

    – Abbadon771
    Nov 23 '18 at 7:24






  • 1





    Are you sure _username is not None?

    – Benjámin Budai
    Nov 23 '18 at 21:24














0












0








0








I am creating a web application login page where the user inputs their login information and the app will take their login information, compare it to what is in the database then determine if the login is a registered user. I am starting off by doing a quick test to see if I can get the value from the database, however the problem I am having is that when I input the specific value form the user input that I want it to find, I keep getting an error stating that the value needs to be a specific parameter, row or tuple. I am using an sql server



@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
try:
connect = pypyodbc.connect('Driver={SQL server};Server=localhost;Database=capstone;uid=;pwd=')
cursor = connect.cursor()
_username = str(request.form['username'])
cursor.execute("SELECT * FROM login WHERE username= (%s)", _username)
dataUser = cursor.fetchone()[1]
return(dataUser)
except Exception as e:
return (str(e))









share|improve this question














I am creating a web application login page where the user inputs their login information and the app will take their login information, compare it to what is in the database then determine if the login is a registered user. I am starting off by doing a quick test to see if I can get the value from the database, however the problem I am having is that when I input the specific value form the user input that I want it to find, I keep getting an error stating that the value needs to be a specific parameter, row or tuple. I am using an sql server



@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
try:
connect = pypyodbc.connect('Driver={SQL server};Server=localhost;Database=capstone;uid=;pwd=')
cursor = connect.cursor()
_username = str(request.form['username'])
cursor.execute("SELECT * FROM login WHERE username= (%s)", _username)
dataUser = cursor.fetchone()[1]
return(dataUser)
except Exception as e:
return (str(e))






python sql-server database web-applications






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 22:30









Abbadon771Abbadon771

63




63








  • 1





    You are testing with an SQL wildcard in the where condition. Use ? as a parameter marker instead of %s.

    – Benjámin Budai
    Nov 22 '18 at 22:48











  • I have tried with ? and it still wouldn't work

    – Abbadon771
    Nov 23 '18 at 7:24






  • 1





    Are you sure _username is not None?

    – Benjámin Budai
    Nov 23 '18 at 21:24














  • 1





    You are testing with an SQL wildcard in the where condition. Use ? as a parameter marker instead of %s.

    – Benjámin Budai
    Nov 22 '18 at 22:48











  • I have tried with ? and it still wouldn't work

    – Abbadon771
    Nov 23 '18 at 7:24






  • 1





    Are you sure _username is not None?

    – Benjámin Budai
    Nov 23 '18 at 21:24








1




1





You are testing with an SQL wildcard in the where condition. Use ? as a parameter marker instead of %s.

– Benjámin Budai
Nov 22 '18 at 22:48





You are testing with an SQL wildcard in the where condition. Use ? as a parameter marker instead of %s.

– Benjámin Budai
Nov 22 '18 at 22:48













I have tried with ? and it still wouldn't work

– Abbadon771
Nov 23 '18 at 7:24





I have tried with ? and it still wouldn't work

– Abbadon771
Nov 23 '18 at 7:24




1




1





Are you sure _username is not None?

– Benjámin Budai
Nov 23 '18 at 21:24





Are you sure _username is not None?

– Benjámin Budai
Nov 23 '18 at 21:24












1 Answer
1






active

oldest

votes


















0














There's a couple ways you can do this:



# using dictionary
values = {'username': _username, }
cursor.execute("SELECT * FROM login WHERE username=:username", values)

#using tuple:
values = (_username,)
cursor.execute("SELECT * FROM login WHERE username=? ", values)
# Using fetchone will return the object and not an array.
# No need for [1] in 'cursor.fetchone()[1]'
return cursor.fetchone()





share|improve this answer


























  • neither of these options work, I still get this message: Params must be in a list, tuple, or Row. It is weird because I try cursor.execute("SELECT * FROM login WHERE username='admin89'") and it does return the password

    – Abbadon771
    Nov 23 '18 at 19:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438669%2fpython-finding-a-specific-value-in-a-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














There's a couple ways you can do this:



# using dictionary
values = {'username': _username, }
cursor.execute("SELECT * FROM login WHERE username=:username", values)

#using tuple:
values = (_username,)
cursor.execute("SELECT * FROM login WHERE username=? ", values)
# Using fetchone will return the object and not an array.
# No need for [1] in 'cursor.fetchone()[1]'
return cursor.fetchone()





share|improve this answer


























  • neither of these options work, I still get this message: Params must be in a list, tuple, or Row. It is weird because I try cursor.execute("SELECT * FROM login WHERE username='admin89'") and it does return the password

    – Abbadon771
    Nov 23 '18 at 19:31
















0














There's a couple ways you can do this:



# using dictionary
values = {'username': _username, }
cursor.execute("SELECT * FROM login WHERE username=:username", values)

#using tuple:
values = (_username,)
cursor.execute("SELECT * FROM login WHERE username=? ", values)
# Using fetchone will return the object and not an array.
# No need for [1] in 'cursor.fetchone()[1]'
return cursor.fetchone()





share|improve this answer


























  • neither of these options work, I still get this message: Params must be in a list, tuple, or Row. It is weird because I try cursor.execute("SELECT * FROM login WHERE username='admin89'") and it does return the password

    – Abbadon771
    Nov 23 '18 at 19:31














0












0








0







There's a couple ways you can do this:



# using dictionary
values = {'username': _username, }
cursor.execute("SELECT * FROM login WHERE username=:username", values)

#using tuple:
values = (_username,)
cursor.execute("SELECT * FROM login WHERE username=? ", values)
# Using fetchone will return the object and not an array.
# No need for [1] in 'cursor.fetchone()[1]'
return cursor.fetchone()





share|improve this answer















There's a couple ways you can do this:



# using dictionary
values = {'username': _username, }
cursor.execute("SELECT * FROM login WHERE username=:username", values)

#using tuple:
values = (_username,)
cursor.execute("SELECT * FROM login WHERE username=? ", values)
# Using fetchone will return the object and not an array.
# No need for [1] in 'cursor.fetchone()[1]'
return cursor.fetchone()






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 21:27

























answered Nov 22 '18 at 23:47









Marcelo FonsecaMarcelo Fonseca

598




598













  • neither of these options work, I still get this message: Params must be in a list, tuple, or Row. It is weird because I try cursor.execute("SELECT * FROM login WHERE username='admin89'") and it does return the password

    – Abbadon771
    Nov 23 '18 at 19:31



















  • neither of these options work, I still get this message: Params must be in a list, tuple, or Row. It is weird because I try cursor.execute("SELECT * FROM login WHERE username='admin89'") and it does return the password

    – Abbadon771
    Nov 23 '18 at 19:31

















neither of these options work, I still get this message: Params must be in a list, tuple, or Row. It is weird because I try cursor.execute("SELECT * FROM login WHERE username='admin89'") and it does return the password

– Abbadon771
Nov 23 '18 at 19:31





neither of these options work, I still get this message: Params must be in a list, tuple, or Row. It is weird because I try cursor.execute("SELECT * FROM login WHERE username='admin89'") and it does return the password

– Abbadon771
Nov 23 '18 at 19:31


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438669%2fpython-finding-a-specific-value-in-a-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python