affordit Posted February 24, 2008 Share Posted February 24, 2008 Can someone tell me whats wrong with this update query? $i = 0; while ($info = mysql_fetch_array($result)) { $acctnum = createAcctNum(); // UPDATE THE ROW // $update = "UPDATE `test` SET `acct_num`= . $city . '-' . $acctnum . '-' . $info['id'] WHERE `id`=" . $info['id'] or die (mysql_error()); mysql_query($update); echo "updated" . $username; $i++; } Link to comment https://forums.phpfreaks.com/topic/92767-not-updating/ Share on other sites More sharing options...
schilly Posted February 24, 2008 Share Posted February 24, 2008 Try this and see if you get an error <?php $update = "UPDATE `test` SET `acct_num`= $city-$acctnum-" . $info['id'] . " WHERE `id`=" . $info['id']; mysql_query($update) or die (mysql_error()); echo "updated" . $username; $i++; } ?> Link to comment https://forums.phpfreaks.com/topic/92767-not-updating/#findComment-475306 Share on other sites More sharing options...
affordit Posted February 24, 2008 Author Share Posted February 24, 2008 Unknown column 'KLA' in 'field list' (This is the city var) Link to comment https://forums.phpfreaks.com/topic/92767-not-updating/#findComment-475315 Share on other sites More sharing options...
schilly Posted February 24, 2008 Share Posted February 24, 2008 Echo the $update sting and post it. I'm thinking you need quotes around the account_num value. $update = "UPDATE `test` SET `acct_num`= '$city-$acctnum-" . $info['id'] . "' WHERE `id`=" . $info['id']; Link to comment https://forums.phpfreaks.com/topic/92767-not-updating/#findComment-475317 Share on other sites More sharing options...
affordit Posted February 24, 2008 Author Share Posted February 24, 2008 Just a blank page Link to comment https://forums.phpfreaks.com/topic/92767-not-updating/#findComment-475329 Share on other sites More sharing options...
affordit Posted February 25, 2008 Author Share Posted February 25, 2008 Just a blank page Link to comment https://forums.phpfreaks.com/topic/92767-not-updating/#findComment-475462 Share on other sites More sharing options...
Bauer418 Posted February 25, 2008 Share Posted February 25, 2008 <?php $update = "UPDATE `test` SET `acct_num`='" . mysql_real_escape_string($city . '-' . $acctnum . '-' . $info['id']) . "' WHERE `id`='" . mysql_real_escape_string($info['id']) . "'"; mysql_query($update) or die (mysql_error()); echo "updated" . $username; $i++; } ?> I may have gone overboard with mysql_real_escape_string, but you should always be cleaning your variables before using them in a query. Link to comment https://forums.phpfreaks.com/topic/92767-not-updating/#findComment-475466 Share on other sites More sharing options...
affordit Posted February 25, 2008 Author Share Posted February 25, 2008 Thanks work great Link to comment https://forums.phpfreaks.com/topic/92767-not-updating/#findComment-475483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.