Jump to content

Help with SELECT = NULL


Topshed

Recommended Posts

I have a Select WHERE query that I cannot get to work with a NULL in a VARCHAR field

 

I input 2 variables

 

$modnum = 12204;
$suff = 'NULL'
.
.
.
.
.
.
$db="SELECT * FROM $tble WHERE model = $modnum AND sufix = '$suff'";

 

 

Sufix can have from Null to 6 chars in the varchar field,

If I put in a valid input like  A,  DL,  EX,  it works fine but if I leave it blank it dies

 

I have tried all sorts of inputs like

$suff = 'NULL'

$suff = ''

$suff = '  '

$suff = '      '

 

I am still new to this stuff and a google does not find me an answer

 

Please help me someone

 

Thanks

Roy...

Link to comment
https://forums.phpfreaks.com/topic/86300-help-with-select-null/
Share on other sites

Thanks for the reply

 

but it still bombs with a NULL

 

$modnum = 11101;
$suff = 'NULL'

    $db = "SELECT * FROM $tble WHERE model = $modnum ";
    if ($suff == 'null') {   
        //don't add the AND statement.
    } else {
         $db .= "AND sufix = '$suff'";
    }
if ($result = mysqli_query($connect,$db)) {  
	if (mysqli_num_rows($result)) {
			while ($row = mysqli_fetch_assoc($result)){

 

What am I missing

 

regards

Roy

Link to comment
https://forums.phpfreaks.com/topic/86300-help-with-select-null/#findComment-441382
Share on other sites

I don't think NULL is equal to null.

$modnum = 11101;
$suff = 'NULL'

    $db = "SELECT * FROM $tble WHERE model = '$modnum' ";
    if (strtolower($suff) == 'null') {   
        //don't add the AND statement.
    } else {
         $db .= "AND sufix = '$suff'";
    }
if ($result = mysqli_query($connect,$db)) {  
	if (mysqli_num_rows($result)) {
			while ($row = mysqli_fetch_assoc($result)){

Link to comment
https://forums.phpfreaks.com/topic/86300-help-with-select-null/#findComment-441641
Share on other sites

I have a Select WHERE query that I cannot get to work with a NULL in a VARCHAR field

 

I input 2 variables

 

$modnum = 12204;
$suff = 'NULL'
.
.
.
.
.
.
$db="SELECT * FROM $tble WHERE model = $modnum AND sufix = '$suff'";

 

 

Sufix can have from Null to 6 chars in the varchar field,

If I put in a valid input like  A,  DL,  EX,  it works fine but if I leave it blank it dies

 

I have tried all sorts of inputs like

$suff = 'NULL'

$suff = ''

$suff = '  '

$suff = '      '

 

I am still new to this stuff and a google does not find me an answer

 

Please help me someone

 

Thanks

Roy...

 

$stuff = NULL;

 

No quotes bud...

Also, for the if

 

if ($stuff == NULL) {
}

 

or you can do

 

if (!$stuff) {
}

Link to comment
https://forums.phpfreaks.com/topic/86300-help-with-select-null/#findComment-441722
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.