Guitarrenchip Posted August 26, 2021 Share Posted August 26, 2021 I want to check if the User has typed it in correctly controlling on the Database. (The echos are just there for debug reasons) if (isset($_POST['aktion']) and $_POST['aktion']=='Annehmen') { //button click echo '<p>1</p>'; $email = ""; if (isset($_POST['email'])) { //steht was da? $email = (INT) trim($_POST['email']); echo '<p>2</p>'; if ($email != '') { //steht was da? 2.0 $suche = $db->prepare("SELECT email FROM recipients WHERE email = ?"); $suche->bind_param('s', $email); $emailtest = ""; $suche->execute(); $suche->bind_result($emailtest); echo '<p>3</p>'; if ($email == $emailtest){ echo '<p>4</p>'; } } } } The debug reaches "Milestone" 3, then its trace disappears, doesn't matter whether it's the right or wrong email. THX for help in advance :). Quote Link to comment https://forums.phpfreaks.com/topic/313608-i-want-to-check-if-the-user-has-typed-it-in-correctly-controlling-on-the-database/ Share on other sites More sharing options...
Barand Posted August 26, 2021 Share Posted August 26, 2021 You need to fetch() the record. 1 Quote Link to comment https://forums.phpfreaks.com/topic/313608-i-want-to-check-if-the-user-has-typed-it-in-correctly-controlling-on-the-database/#findComment-1589399 Share on other sites More sharing options...
maxxd Posted August 28, 2021 Share Posted August 28, 2021 You're casting $email as an int, but then binding it as a string. I'm not sure that PHP's loose typing handles that? I use PDO so I rarely bind before execution. Quote Link to comment https://forums.phpfreaks.com/topic/313608-i-want-to-check-if-the-user-has-typed-it-in-correctly-controlling-on-the-database/#findComment-1589411 Share on other sites More sharing options...
ginerjm Posted August 28, 2021 Share Posted August 28, 2021 Besides adding the fetch statement, you might want to check if your query returned any results before even trying to do the fetch. Quote Link to comment https://forums.phpfreaks.com/topic/313608-i-want-to-check-if-the-user-has-typed-it-in-correctly-controlling-on-the-database/#findComment-1589414 Share on other sites More sharing options...
mac_gyver Posted August 28, 2021 Share Posted August 28, 2021 (edited) there's no need to compare, in php code, the column value fetched from the query with the column value being tested in the where clause. if the query matched a row(s) of data, the where clause was true. next, if you are not actually using the row(s) of data that a query matches, i.e. you are only testing if a value exists or how many times it exists, use SELECT COUNT(*) ..., and if this is for a 'registration' script, where you are deciding if you are going to insert a row of data, instead, just define that column as a unique index, attempt to insert the data, then test if the query produced a duplicate error. lastly, if you switch to the much simpler PDO database extension, a majority of the lines of code will go away. Edited August 28, 2021 by mac_gyver 1 Quote Link to comment https://forums.phpfreaks.com/topic/313608-i-want-to-check-if-the-user-has-typed-it-in-correctly-controlling-on-the-database/#findComment-1589424 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.