Jump to content

Update NULL won't work


BDabrowski

Recommended Posts

I have a column in a table that is set to allow NULL, and default is NULL. When a record is inserted, with no value, the field is correctly NULL.

 

Every time I run an UPDATE on the table, the field becomes an empty string. The syntax I'm using is

SET field=NULL, otherfield . . . .etc.

 

I've written the query back to the screen to ensure that it is attempting the proper query. I get no mysql errors, but it keeps setting the field to a empty string.

 

In PHPMyAdmin, if I run the UPDATE query with the SQL tool, it still makes the field an empty string. The only way I can set an existing record back to NULL is to select to edit the record and use PHPMyAdmin's form to run the query.

 

After setting the field back to NULL with the pre-built form, I can even copy and paste the query that the form created back into the SQL tool and it still inserts an empty string rather than NULL, when that exact same query just inserted the NULL value via the form.

 

The host says it's a programming issue. What am I missing?

 

Link to comment
Share on other sites

<?php

$server = "localhost"; //replace this value
$user = "root"; //replace this value
$pass = ""; //replace this value
$db = "xpressde"; //replace this value
$table_name = "clients"; //replace this value
$field_name = "firstname"; //replace this value

mysql_connect($server,$user,$pass);
mysql_select_db($db);

$query = "UPDATE $table_name SET $field_name=NULL";
mysql_query($query);
?>

 

I already tried out that code in my local server, and it works perfectly.

If it doesn't work, it should be something related to the server.

 

Tell them to check the logs, if the server is being run on linux,

they should find all the logs at : /var

Link to comment
Share on other sites

Server version: 5.0.85-community

 

The tables/DB is MyISAM. I've been seeing something about certain  types not allowing NULL.

 

Tried the SHOW CREATE TABLE query, but PHPMyAdmn gave me this:

 

Full Texts
Table 	Create Table
nhb_users 	CREATE TABLE `nhb_users` (
`users_id` int(11) NO...

 

I'm sure there's more to it.

 

I've avoided the issue for now, so feel no obligation to follow up, but I'll still be interested to figure it out.

Link to comment
Share on other sites

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.