oOmega Posted November 9, 2014 Share Posted November 9, 2014 Hello ! First of all, I'm a newbie in php and english isn't my native language. My website : -index.php where the user create his account -signup.php where every test are made, then if succesfull will create the user in the database. The code bellow will be from signup.php. Variables in $_post comes from index.php. DB connect <? php $bdd = new PDO('mysql:host=localhost;dbname=lolstats', 'martin', '');$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); Tests : // Testing if every variables are existing If (Isset($_POST['sign_password']) AND ($_POST['sign_pseudo']) AND ($_POST['sign_email']) AND ($_POST['sign_password2']) ) { $email= $_POST['sign_email'] ; $user= $_POST['sign_pseudo'] ; $test = $bdd->prepare('SELECT pseudo FROM membres WHERE pseudo= ? OR email = ? ') ; $test -> execute(array ( $user, $email) ); while ($test_test=$test->fetch()) { // testing if the user is already in the database if ( $test_test === NULL ) { // testing if the password match if ( ($_POST['sign_password']) == ($_POST['sign_password2']) ){ // Crypting $pass_hache = sha1($_POST['sign_password']); // Insert $test->closeCursor(); $req = $bdd->prepare('INSERT INTO membres (pseudo, pass, email, date_inscription) VALUES(?, ?, ?, sysdate())'); $req->execute(array($_POST['sign_pseudo'], $pass_hache, $_POST['sign_email'])); echo '<p> Account Created ! </p>' ; } ELSE { echo '<p>Non matching passwords</p>' ; } } ELSE { echo '<p>User / Email already in used' ; } } } ELSE { echo '<p>Please, enter every information needed</p>'; } ?> The line in red is where I think the problem is. So, let's say $test_test <> NULL, then the else function just fine. ELSE { echo '<p>User / Email already in used' ; } But it seems like I never goes "inside" the $test_test == NULL. I'm saying that because the next if is working fine if I test it alone, but once put inside the if == NULL, it doesn't work anymore. I hope I made myself clear, please ask if there are some logic you don't understand in my code. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/292371-subsequent-if-not-working/ Share on other sites More sharing options...
requinix Posted November 9, 2014 Share Posted November 9, 2014 So it always says that user/email in use message? That must mean if ( $test_test === NULL ) {was never true. Well, what is the value of $test_test? It comes from while ($test_test=$test->fetch()) {and $test came from $test = $bdd->prepare('SELECT pseudo FROM membres WHERE pseudo= ? OR email = ? ') ;That means $test is a PDOStatement object and $test->fetch is PDOStatement::fetch. If you look at the documentation you'll see that is says (in English), The return value of this function on success depends on the fetch type. In all cases, FALSE is returned on failure.It never returns null. That's why $test_test === NULL is never true. Quote Link to comment https://forums.phpfreaks.com/topic/292371-subsequent-if-not-working/#findComment-1496156 Share on other sites More sharing options...
oOmega Posted November 9, 2014 Author Share Posted November 9, 2014 Tried with FALSE, doesn't work either. Tried this while ($test_test=$test->fetch()) { print_r($test_test); } When the user already exist, it contains his pseudo / email When the user doesn't exist, I get a blank page with noothing written. Which means it contains NULL no ? Or it would show me NULL ? Quote Link to comment https://forums.phpfreaks.com/topic/292371-subsequent-if-not-working/#findComment-1496159 Share on other sites More sharing options...
oOmega Posted November 9, 2014 Author Share Posted November 9, 2014 So it always says that user/email in use message? That must mean if ( $test_test === NULL ) { was never true. No, when the user / email is not already in use, I get a blank page. It looks like it's kind of working, because if it's in use, it's working perfectly. If user/email not in use, then nothing happens. It's like I don't enter the next if. But when I try the next IF alone, it works juste fine. (the password = password2 one). Quote Link to comment https://forums.phpfreaks.com/topic/292371-subsequent-if-not-working/#findComment-1496161 Share on other sites More sharing options...
oOmega Posted November 9, 2014 Author Share Posted November 9, 2014 Problem solved. The while was the problem. I just took it off, now it's working ! Quote Link to comment https://forums.phpfreaks.com/topic/292371-subsequent-if-not-working/#findComment-1496164 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.