Jump to content

Recommended Posts

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(); ?>

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

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>';                }
 
?>

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...;

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.