PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
SELECT `field` FROM `table_name` WHERE `field` IS NULL;
SELECT `field` FROM `table_name` WHERE `field` IS NOT NULL;
That's all there is to it.
You've not really answered the question.
If you saw the screenshot, you can see the field IS set to allow a Null value.
I can only do a UPDATE query for null if that is what is passed through from the form, of by converting a value to a NULL - which is what I am asking about here.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Ohhh so close. It is converting the field to a NULL value, but it is converting both 'application' and 'category' to NULL whatever is passed through. ie, if "boat" is passed through, it still sets it to null.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
I'm sorry, are you trying to confuse me?
You use one method that half works, a method I cannot quite work out.
They you say it is a teaser, and give me an alternative method.
It works - but only sets all to NULL - why is that?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
$category = $_POST['category'] == 'none' //If the value of category is equal to 'none'
? 'NULL' //Then the value is NULL
: ("'" . $_POST['category'] . "'"); //Otherwise quote the string value
The important thing is, as Jonah said previously, that the NULL value should not be quoted while string value should be quoted.
This when I say "none" to categories and "boat" to applications, puts boat into the applications field and just leaves the category field empty, but does not set it to NULL.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis wrote:Thanks, but you have not given any indication of where that should go in the script.
You really need to rethink your process. You need quotes around the column value in the query if its a string, especially if it has spaces, but you can't have quotes around it if its NULL. So you need to determine whether the value should be NULL and insert it without quotes or if it is a string (category name) and quote it.
$category = $category == 'none' ? 'NULL' : "'$category'";
$query = mysql_query ("UPDATE products SET
category = $category,
application = '$application',
title = '$title',
description = '$description',
video = '$video'
WHERE id = '$id'");
Last edited by AbraCadaver on Tue Jun 08, 2010 12:15 pm, edited 1 time in total.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.