Hi all!
I would call myself a 'Newbie' and have been browsing through many forum lists and manuals to solve following problem, without any success:
I have a form where I want to update values. The updating functions very well, in case I do not use the update to delete the values in a field.
The statement which I use within mysql_query("...");
functions very well in the shell, but not via the PHP-script:
UPDATE employees SET telephone=''
(respectively - SET telefon=NULL) WHERE id=2;
That's how it all looks-
// I'm asking whether the variables $telephone or
// $roomNo exist
if ($telephone | $roomNo)
{
$my_query ="update mitarbeiter set ";
if ($telephone=="") {
$my_query .= "telephone=NULL";
} else {
$my_query .= "telephone ='$telephone'";
}
...//some other if-statements
$my_query .= "where id=$id;";
$result = mysql_query($my_query);
}
if ($telephone=="") functions as well as else{..} is ok, depending on the value in the field that I submitted. (NULL or something)
I tested $telephone (when having deleted the values in the telephone-field) with strlen() and it said 0. So the variable $telephone always exists.
I can put whatever in
$my_query .= "telephone ='whatever'";
or a new variable like $nothing which I defined some rows up.
It doesn't work when $telephone is empty, that is null.
It only works when there is stored a value in $telephone.
My "employees"-table should be ok, there's no "NOT NULL" set for telephone or so. It is no key either.
Is there anyone here who knows who I could solve this?
Thanks a lot in advance,
marion
I would call myself a 'Newbie' and have been browsing through many forum lists and manuals to solve following problem, without any success:
I have a form where I want to update values. The updating functions very well, in case I do not use the update to delete the values in a field.
The statement which I use within mysql_query("...");
functions very well in the shell, but not via the PHP-script:
UPDATE employees SET telephone=''
(respectively - SET telefon=NULL) WHERE id=2;
That's how it all looks-
// I'm asking whether the variables $telephone or
// $roomNo exist
if ($telephone | $roomNo)
{
$my_query ="update mitarbeiter set ";
if ($telephone=="") {
$my_query .= "telephone=NULL";
} else {
$my_query .= "telephone ='$telephone'";
}
...//some other if-statements
$my_query .= "where id=$id;";
$result = mysql_query($my_query);
}
if ($telephone=="") functions as well as else{..} is ok, depending on the value in the field that I submitted. (NULL or something)
I tested $telephone (when having deleted the values in the telephone-field) with strlen() and it said 0. So the variable $telephone always exists.
I can put whatever in
$my_query .= "telephone ='whatever'";
or a new variable like $nothing which I defined some rows up.
It doesn't work when $telephone is empty, that is null.
It only works when there is stored a value in $telephone.
My "employees"-table should be ok, there's no "NOT NULL" set for telephone or so. It is no key either.
Is there anyone here who knows who I could solve this?
Thanks a lot in advance,
marion