PeterPopper Posted April 13, 2010 Share Posted April 13, 2010 I have a database with one table and one row, the row is listNumber. I want to update and retrieve the value of listNumber but maintain just one row in the table. The problem is that if I use INSET, it works fine, but UPDATE, as in my code below, is not working. I don't want to use INSERT because it creates a new record each time. Update: $sql="UPDATE MainTable SET listNumber='$theNewCount'"; Retrieve: $sql="Select listNumber FROM MainTable; Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/198390-store-and-update-only-one-record-in-mysql-table/ Share on other sites More sharing options...
Ken2k7 Posted April 13, 2010 Share Posted April 13, 2010 That should work. Why's it not working? Quote Link to comment https://forums.phpfreaks.com/topic/198390-store-and-update-only-one-record-in-mysql-table/#findComment-1041008 Share on other sites More sharing options...
PeterPopper Posted April 13, 2010 Author Share Posted April 13, 2010 Well, the table is currently empty to begin with, and maybe that is the problem. I am not sure. Quote Link to comment https://forums.phpfreaks.com/topic/198390-store-and-update-only-one-record-in-mysql-table/#findComment-1041015 Share on other sites More sharing options...
Ken2k7 Posted April 13, 2010 Share Posted April 13, 2010 If it's empty, use INSERT. If not, use UPDATE. Kind of self-explanatory, isn't it? Quote Link to comment https://forums.phpfreaks.com/topic/198390-store-and-update-only-one-record-in-mysql-table/#findComment-1041020 Share on other sites More sharing options...
PFMaBiSmAd Posted April 13, 2010 Share Posted April 13, 2010 http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html Quote Link to comment https://forums.phpfreaks.com/topic/198390-store-and-update-only-one-record-in-mysql-table/#findComment-1041042 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.