benoit1980 Posted July 21, 2013 Share Posted July 21, 2013 Hello, I have no idea what I am doing wrong. I am trying to return the matching $prefixphone value only if there is a "null" value found in the column. I have been stuck on this for 2 hours, I cannot find a solution. please help, Thank you, Ben <?php $stmt = $mysqli->prepare("SELECT * FROM $tbl_name WHERE phone_number=? AND WHERE group_leader=?"); /* Bind our params */ $prefixphone = '987979879'; $group_leader ='IS NULL'; $stmt->bind_param('ss', $prefixphone, $group_leader); /* Execute it */ $result = $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 1) { echo '<div align="center" class="text-not-correct">You are a VIP member!</div>'; /* Close statement */ $stmt->close(); /* Close connection */ $mysqli->close(); ?> Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted July 21, 2013 Share Posted July 21, 2013 (edited) You do not need 2 WHERE clauses. "SELECT * FROM $tbl_name WHERE phone_number=? AND group_leader IS NULL" 2 hours well spent Edited July 21, 2013 by PaulRyan Quote Link to comment Share on other sites More sharing options...
benoit1980 Posted July 21, 2013 Author Share Posted July 21, 2013 Hi, Thank you for your help, unfortunately I am still getting error: Fatal error: Call to a member function prepare() on a non-object in /check.php on line 25 Line 25 corresponding to $stmt = $mysqli->prepare("SELECT * FROM $tbl_name WHERE phone_number=? AND group_leader IS NULL"); Any idea what it means please? When I remove this part of the query: AND group_leader IS NULL It seems that the NULL value is causing problem. IS WORKS OK....WEIRD... Thank you, Ben Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted July 21, 2013 Share Posted July 21, 2013 Please post your updated code, so I can see the changes. Quote Link to comment Share on other sites More sharing options...
benoit1980 Posted July 21, 2013 Author Share Posted July 21, 2013 Hi PaulRyan, Thank you for your help, here it is: <?php $prefixphone = $_POST['prefix'].$_POST['phone']; $stmt = $mysqli->prepare("SELECT * FROM $tbl_name WHERE phone_number=? AND group_leader IS NULL"); /* Bind our params */ $stmt->bind_param('s', $prefixphone); /* Execute it */ $result = $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 1) { echo '<div align="center" class="text-not-correct">You are a top member!</div>'; /* Close statement */ $stmt->close(); /* Close connection */ $mysqli->close(); } else { echo '<div align="center" class="text-not-correct">You are not a top member!</div>'; echo '<div align="center" class="text-not-correct">This is the end</div>'; } ?> Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted July 21, 2013 Share Posted July 21, 2013 Try using this: $stmt = $mysqli->prepare("SELECT * FROM $tbl_name WHERE phone_number=? AND group_leader IS NULL") or die($mysqli->error); Quote Link to comment Share on other sites More sharing options...
benoit1980 Posted July 21, 2013 Author Share Posted July 21, 2013 No, unfortunately the same error shows up..........I really don't get it...It works with anything else but not "NULL" has anyone an explanation for it please? Thank you, Ben Quote Link to comment Share on other sites More sharing options...
benoit1980 Posted July 21, 2013 Author Share Posted July 21, 2013 In fact my first problem was really stupid, I did not have a connection :-) But my second problem is that the sql command i actually invalid and returning nothing like that SELECT * FROM vipsreg WHERE phone_number=0035679303062 AND group_leader IS NULL; But returning the right row like this: SELECT * FROM vipsreg WHERE phone_number=0035679303062 Unfortunately I must have the results return for the phone number field if there is a null value found in the group_leader field...; Quote Link to comment Share on other sites More sharing options...
benoit1980 Posted July 21, 2013 Author Share Posted July 21, 2013 Ok now with the connection and this it works : $stmt = $mysqli->prepare("SELECT * FROM $tbl_name WHERE phone_number=? AND group_leader=?"); /* Bind our params */ $null = 'NULL'; $stmt->bind_param('ss', $prefixphone ,$null); Thanks for your help! Ben Quote Link to comment 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.