sofia403 Posted May 29, 2011 Share Posted May 29, 2011 hi , just wondering if this query is missing something or entered incorrect. I'm trying to update a value in db with a Submit from php. thank you. $city = $_POST['city']; if(isset($_POST['Submit'])){ $query=( "INSERT INTO country CITY VALUES '$city'");} Link to comment https://forums.phpfreaks.com/topic/237748-updating-query/ Share on other sites More sharing options...
trq Posted May 29, 2011 Share Posted May 29, 2011 Are you trying to update an existing record or insert a new one? Your post is ambiguous. Link to comment https://forums.phpfreaks.com/topic/237748-updating-query/#findComment-1221769 Share on other sites More sharing options...
sofia403 Posted May 29, 2011 Author Share Posted May 29, 2011 um, well im guessing it will have to be both ? i already have some entry in db, when users log in i just want them to either update existing records or just add a new value in some of the fields. Also i have separate "Update" button for each column. So if "User1" logs in he already has a n entry in "city" so i want him be able to change that value, while "User2" might not have the city in the db yet. Link to comment https://forums.phpfreaks.com/topic/237748-updating-query/#findComment-1221770 Share on other sites More sharing options...
trq Posted May 29, 2011 Share Posted May 29, 2011 Then you will first need to check if the record exists using a SELECT, if so, execute an UPDATE statement, otherwise, execute an INSERT. You could also use the ON DUPLICATE KEY method. All of this is described in the manual. http://dev.mysql.com/doc/refman/5.5/en/insert.html Link to comment https://forums.phpfreaks.com/topic/237748-updating-query/#findComment-1221773 Share on other sites More sharing options...
sofia403 Posted May 30, 2011 Author Share Posted May 30, 2011 MySQL version 5.0.81-community-log Hello, im still trying to find an answer how i can go about creating a query that would update or insert a value based on if an entry already exists or not in a table I'm using the query below, but its not working (not updating nor inserting anything) and i don't get any errors. i copied this query from the web some place and not quite sure if this is best way to go about it. So i have ApplicationStatus column where users input (In Process, Withdrawn and so on)and i want the user when he logs into their profile be able to update that field, they might have a value there or they might have it empty, so its either has to be insert or update i guess? can someone please take a look at it, and point me in the right direction. thank you. also i dont know if mysql version is enough or you might need something else here? I could provide more information if needed. thanks UPDATE country SET ApplicationStatus='1' WHERE ApplicationStatus=echo ('$ApplicationStatus'). IF @@ROWCOUNT=0 INSERT INTO country VALUES '$_POST[ApplicationStatus]' Link to comment https://forums.phpfreaks.com/topic/237748-updating-query/#findComment-1222500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.