Strange MySQL Problem

Associate
Joined
27 Jun 2008
Posts
1,538
I'm having a strange problem with updating fields in MySQL with PHP and making a field NULL or ''. It only does it when I try to edit the field the second time. Below is an example of the queries I'm using. These queries work perfectly fine through the MySQL Command Line console but the last one fails when done through PHP.

Code:
CREATE TABLE mytable (id SMALLINT UNSIGNED NOT NULL PRIMARY KEY, mytext VARCHAR(96)); - Initial table, created using command console.

INSERT INTO mytable SET id = '1', mytext = 'Hello World!'; - Works fine.

UPDATE mytable SET myfield =  '' WHERE id = '1'; - Works fine.

UPDATE mytable SET myfield =  'Some new text' WHERE id = '1'; - Works fine.

UPDATE mytable SET myfield =  '' WHERE id = '1'; - Doesn't work, still displays "Some new text". However, it will work if I change the value to anything other than leaving it empty.

The query must be failing some how on the PHP side. This is all done through AJAX. The code below is from the file containing the query:

Code:
<?php
include 'opendb.php';
$sid = $_GET['sid_e'];$sname = $_GET['sname_e'];$loc_sec = $_GET['loc_sec_e'];$loc_col = $_GET['loc_col_e'];$loc_row = $_GET['loc_row_e'];$notes = $_GET['notes_e'];
$loc_sec_u = strtoupper($loc_sec);
mysql_query("UPDATE suppliers SET sname = '$sname', loc_sec = '$loc_sec_u', loc_col = '$loc_col', loc_row = '$loc_row', notes = '$notes' WHERE sid = '$sid'") or die(mysql_error());
mysql_close($db_connect);
?>

This is the AJAX code applying to this:

Code:
	xmlHttp.open("GET", "data_supplierlist_edit.php?sid_e=" + gDID + "&sname_e=" + document.getElementById("sname_e").value + "&loc_sec_e=" + document.getElementById("loc1_e").value + "&loc_col_e=" + document.getElementById("loc2_e").value + "&loc_row_e=" + document.getElementById("loc3_e").value + "&notes_e=" + document.getElementById("notes_e").value, true);

I hope I explained it well enough as it's a strange problem that only occurs in the circumstances above.
 
After testing a bit more it turns out that it was a IE problem. It works fine it other browsers (Opera, Chrome). Guess that'll teach me for using it to develop a web page. :p

Thanks anyway.
 
Not really. It did work if I updated another field along with it but otherwise the problem still persisted. It could just be IE not updating its cache files.
 
Back
Top Bottom