Skip to main content

MySQL Query doesn"t update rows


I've got a weird problem here. I've been trying to find out whats wrong for several hours now. I've got a function that should update a table in my database and set the "date_vente" (date_sold for english) to NOW(). The query is mighty simple but it keeps reporting 1 matched row, 0 changed.



Problem is, the data should be changed. If i run the query manually, it works fine, if i run it from the php app, it fails...




//Marque le panier comme vendu
$sqlstring = "UPDATE ".$prefix_tables_panier."paniers SET date_vente = NOW() WHERE no_panier = ".$data_panier["no_panier"];
$result = mysql_query($sqlstring, $conn_panier);
echo $sqlstring.'<br>';
echo mysql_affected_rows($conn_panier); echo '<br>';
echo mysql_error($conn_panier); echo '<br>';
echo mysql_errno($conn_panier); echo '<br>';
var_dump($conn_panier); echo '<br>';
var_dump(mysql_error($conn_panier)); echo '<br>';
var_dump(mysql_info($conn_panier)); echo '<br>';
var_dump(mysql_stat($conn_panier)); echo '<br>';



And the output is




UPDATE panier_paniers SET date_vente = NOW() WHERE no_panier = 840
0

0
resource(5) of type (mysql link)
string(0) ""
string(40) "Rows matched: 1 Changed: 0 Warnings: 0"
string(145) "Uptime: 1640423 Threads: 5 Questions: 39673341 Slow queries: 0 Opens: 1132 Flush tables: 1 Open tables: 235 Queries per second avg: 24.185" 7



The problem is it should write a value of NOW to the table containing the baskets but it is not. And no, it's not because of a wrong connection, the same connection id (var_dumped it) is used in the function just before, calling it and they both have the same id, the connection is still open and there is a value of "0000-00-00 00:00:00" in the column i'm trying to update...



Can anyone give me some more hints to look at?



Thanks





UPDATE




UPDATE panier_paniers SET date_vente = NOW() WHERE no_panier = 840
0

0
resource(5) of type (mysql link)
string(0) ""
string(40) "Rows matched: 1 Changed: 0 Warnings: 0"
string(145) "Uptime: 1641927 Threads: 5 Questions: 39681590 Slow queries: 0 Opens: 1132 Flush tables: 1 Open tables: 235 Queries per second avg: 24.168"

UPDATE panier_paniers SET date_vente = "2011-12-28 12:00:17" WHERE no_panier = 840
1

0
resource(5) of type (mysql link)
string(0) ""
string(40) "Rows matched: 1 Changed: 1 Warnings: 0"
string(145) "Uptime: 1641927 Threads: 5 Questions: 39681591 Slow queries: 0 Opens: 1132 Flush tables: 1 Open tables: 235 Queries per second avg: 24.168"
go



This is getting weird, VERY VERY WEIRD!





UPDATE #2




CREATE TABLE IF NOT EXISTS `panier_paniers` (
`no_panier` bigint(20) unsigned NOT NULL auto_increment,
`client_prenom` varchar(100) NOT NULL default '',
`client_nom` varchar(100) NOT NULL default '',
`client_entreprise` varchar(150) default NULL,
`client_adresse` varchar(150) NOT NULL default '',
`client_ville` varchar(150) NOT NULL default '',
`client_province_etat` char(2) default NULL,
`client_pays` char(2) NOT NULL default '',
`client_code_postal_zip` varchar(15) NOT NULL default '',
`client_telephone` varchar(20) NOT NULL default '',
`client_type_telephone` enum('domicile','travail','cellulaire') NOT NULL default 'domicile',
`client_telecopieur` varchar(20) default NULL,
`client_courriel` varchar(150) NOT NULL default '',
`client_mailinglist_from` datetime default NULL,
`client_langue` char(2) NOT NULL default '',
`client_no_client` bigint(20) unsigned default NULL,
`expedition_mode` varchar(20) NOT NULL default '',
`expedition_no_livraison` bigint(20) unsigned default NULL,
`expedition_produit` varchar(100) default NULL,
`expedition_produit_no_compte` varchar(100) default NULL,
`expedition_frais_livraison` decimal(10,2) NOT NULL default '0.00',
`expedition_frais_manut` decimal(10,2) NOT NULL default '0.00',
`expedition_assurance` char(1) NOT NULL default 'X',
`expedition_signature` char(1) NOT NULL default 'X',
`expedition_conf_livraison` char(1) NOT NULL default 'X',
`expedition_emballage` text,
`expedition_no_suivi` varchar(100) default NULL,
`expedition_prenom` varchar(100) default NULL,
`expedition_nom` varchar(100) default NULL,
`expedition_entreprise` varchar(150) default NULL,
`expedition_adresse` varchar(150) default NULL,
`expedition_ville` varchar(150) default NULL,
`expedition_province_etat` char(2) default NULL,
`expedition_pays` char(2) default NULL,
`expedition_code_postal_zip` varchar(15) default NULL,
`expedition_telephone` varchar(20) default NULL,
`expedition_type_telephone` enum('domicile','travail','cellulaire') NOT NULL default 'domicile',
`expedition_exporte_ups_connect` char(1) NOT NULL default '',
`expedition_mis_a_jour_ups_connect` char(1) NOT NULL default '',
`paiement_mode` varchar(20) NOT NULL default '',
`paiement_no_paiement` bigint(20) unsigned default NULL,
`paiement_numero_taxe_fed` bigint(20) unsigned NOT NULL default '0',
`paiement_numero_taxe_prov` bigint(20) unsigned NOT NULL default '0',
`paiement_numeros_taxes_speciales` varchar(255) NOT NULL,
`paiement_numero_po` varchar(20) default NULL,
`paiement_numero_bon` varchar(20) default NULL,
`paiement_cc_pa_trnid` varchar(10) default NULL,
`paiement_cc_pa_montant` decimal(10,2) NOT NULL default '0.00',
`paiement_cc_capture` text,
`paiement_desjardins_TxID` varchar(25) default NULL,
`paiement_desjardins_date_envoi` datetime NOT NULL default '0000-00-00 00:00:00',
`date_creation` datetime NOT NULL default '0000-00-00 00:00:00',
`ip_creation` varchar(15) NOT NULL default '',
`host_creation` varchar(255) default NULL,
`date_vente` datetime NOT NULL default '0000-00-00 00:00:00',
`date_annulee` datetime NOT NULL default '0000-00-00 00:00:00',
`date_completee` datetime NOT NULL default '0000-00-00 00:00:00',
`date_inventaire` datetime NOT NULL default '0000-00-00 00:00:00',
`date_acceptation` datetime NOT NULL default '0000-00-00 00:00:00',
`note` text,
`note_client` text,
`no_utilisateur` bigint(20) unsigned default NULL,
PRIMARY KEY (`no_panier`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=841 ;





UPDATE #3



Ok, look at this spooky thing:




//Marque le panier comme vendu
$sqlstring = 'UPDATE panier_paniers SET date_vente = NOW() WHERE no_panier = '.$data_panier["no_panier"];
$result = mysql_query($sqlstring, $conn_panier);
echo $sqlstring.'<br>';
echo mysql_affected_rows($conn_panier); echo '<br>';
echo mysql_error($conn_panier); echo '<br>';
echo mysql_errno($conn_panier); echo '<br>';
var_dump($conn_panier); echo '<br>';
var_dump(mysql_error($conn_panier)); echo '<br>';
var_dump(mysql_info($conn_panier)); echo '<br>';
var_dump(mysql_stat($conn_panier)); echo '<br>';

$sqlstring='UPDATE panier_paniers SET date_vente = "2011-12-28 10:09:12" WHERE no_panier = '.$data_panier["no_panier"];
mysql_query($sqlstring, $conn_panier);
echo $sqlstring.'<br>';
echo mysql_affected_rows($conn_panier); echo '<br>';
echo mysql_error($conn_panier); echo '<br>';
echo mysql_errno($conn_panier); echo '<br>';
var_dump($conn_panier); echo '<br>';
var_dump(mysql_error($conn_panier)); echo '<br>';
var_dump(mysql_info($conn_panier)); echo '<br>';
var_dump(mysql_stat($conn_panier)); echo '<br>';



As you can see, both should be valid, the first one will not update anything, the second does update the row. Switch around and test again:




$sqlstring='UPDATE panier_paniers SET date_vente = "2011-12-28 10:09:12" WHERE no_panier = '.$data_panier["no_panier"];
mysql_query($sqlstring, $conn_panier);
echo $sqlstring.'<br>';
echo mysql_affected_rows($conn_panier); echo '<br>';
echo mysql_error($conn_panier); echo '<br>';
echo mysql_errno($conn_panier); echo '<br>';
var_dump($conn_panier); echo '<br>';
var_dump(mysql_error($conn_panier)); echo '<br>';
var_dump(mysql_info($conn_panier)); echo '<br>';
var_dump(mysql_stat($conn_panier)); echo '<br>';

//Marque le panier comme vendu
$sqlstring = 'UPDATE panier_paniers SET date_vente = NOW() WHERE no_panier = '.$data_panier["no_panier"];
$result = mysql_query($sqlstring, $conn_panier);
echo $sqlstring.'<br>';
echo mysql_affected_rows($conn_panier); echo '<br>';
echo mysql_error($conn_panier); echo '<br>';
echo mysql_errno($conn_panier); echo '<br>';
var_dump($conn_panier); echo '<br>';
var_dump(mysql_error($conn_panier)); echo '<br>';
var_dump(mysql_info($conn_panier)); echo '<br>';
var_dump(mysql_stat($conn_panier)); echo '<br>';



RESULT:




UPDATE panier_paniers SET date_vente = "2011-12-28 10:09:12" WHERE no_panier = 840
1

0
resource(5) of type (mysql link)
string(0) ""
string(40) "Rows matched: 1 Changed: 1 Warnings: 0"
string(145) "Uptime: 1643141 Threads: 5 Questions: 39713580 Slow queries: 0 Opens: 1286 Flush tables: 1 Open tables: 219 Queries per second avg: 24.169"
UPDATE panier_paniers SET date_vente = NOW() WHERE no_panier = 840
1

0
resource(5) of type (mysql link)
string(0) ""
string(40) "Rows matched: 1 Changed: 1 Warnings: 0"
string(145) "Uptime: 1643141 Threads: 5 Questions: 39713581 Slow queries: 0 Opens: 1286 Flush tables: 1 Open tables: 219 Queries per second avg: 24.169"



Now both updates work... I tried a verify, repair and optimize to see if it wasn't a corruption issue, nothing changed...


Source: Tips4allCCNA FINAL EXAM

Comments

  1. So the problem was after all an issue with logic and bad coding practices. The problem came from the previous programmers who liked to have no structure and place code in weird places. I found the error outside of the scope of what we where looking for.

    I might say, if you get such an error, look for flaws in your code where a same query could be executed right before the current one that SEEMS to fail. That will save you HOURS of trouble looking for a solution that doesn't pertain to the problem at hand.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex