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(); ?> Link to comment https://forums.phpfreaks.com/topic/280369-mysqli-prepared-statement-select-null-query-problem/ Share on other sites More sharing options...
PaulRyan Posted July 21, 2013 Share Posted July 21, 2013 You do not need 2 WHERE clauses. "SELECT * FROM $tbl_name WHERE phone_number=? AND group_leader IS NULL" 2 hours well spent Link to comment https://forums.phpfreaks.com/topic/280369-mysqli-prepared-statement-select-null-query-problem/#findComment-1441575 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 Link to comment https://forums.phpfreaks.com/topic/280369-mysqli-prepared-statement-select-null-query-problem/#findComment-1441578 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. Link to comment https://forums.phpfreaks.com/topic/280369-mysqli-prepared-statement-select-null-query-problem/#findComment-1441579 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>'; } ?> Link to comment https://forums.phpfreaks.com/topic/280369-mysqli-prepared-statement-select-null-query-problem/#findComment-1441582 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); Link to comment https://forums.phpfreaks.com/topic/280369-mysqli-prepared-statement-select-null-query-problem/#findComment-1441583 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 Link to comment https://forums.phpfreaks.com/topic/280369-mysqli-prepared-statement-select-null-query-problem/#findComment-1441585 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...; Link to comment https://forums.phpfreaks.com/topic/280369-mysqli-prepared-statement-select-null-query-problem/#findComment-1441588 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 Link to comment https://forums.phpfreaks.com/topic/280369-mysqli-prepared-statement-select-null-query-problem/#findComment-1441589 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.