acctman Posted October 1, 2008 Share Posted October 1, 2008 looks like i'm going to have to do this the hard way, by posting multiple questions to get this done. From what i'm reading its taking all the from post that have add in them and Updating it into the database. my question is, what if the entry / value doesn't exist in the table already will it perform an insert? foreach ($_POST['add'] as $key => $value) mysql_query("UPDATE $membtable SET m_".$key."='".sql_escape_string(stripslashes($value))."' WHERE m_id=$id"); Quote Link to comment https://forums.phpfreaks.com/topic/126636-update-query-question/ Share on other sites More sharing options...
revraz Posted October 1, 2008 Share Posted October 1, 2008 You can use INSERT with the ON DUPLICATE KEY UPDATE parameter. http://dev.mysql.com/doc/refman/5.0/en/insert.html Quote Link to comment https://forums.phpfreaks.com/topic/126636-update-query-question/#findComment-654847 Share on other sites More sharing options...
acctman Posted October 1, 2008 Author Share Posted October 1, 2008 You can use INSERT with the ON DUPLICATE KEY UPDATE parameter. http://dev.mysql.com/doc/refman/5.0/en/insert.html but as of right now that code would not insert data into an empty field? Quote Link to comment https://forums.phpfreaks.com/topic/126636-update-query-question/#findComment-654852 Share on other sites More sharing options...
revraz Posted October 1, 2008 Share Posted October 1, 2008 I don't understand your question. Are you asking if you can INSERT a new ROW if it doesn't exist or UPDATE it if it does? If so, then what I linked would do it What do you mean by "entry/value" ? Do you mean a field name or do you mean the data? Quote Link to comment https://forums.phpfreaks.com/topic/126636-update-query-question/#findComment-654854 Share on other sites More sharing options...
acctman Posted October 1, 2008 Author Share Posted October 1, 2008 I don't understand your question. Are you asking if you can INSERT a new ROW if it doesn't exist or UPDATE it if it does? If so, then what I linked would do it What do you mean by "entry/value" ? Do you mean a field name or do you mean the data? if i don't change the coding below, will a blank field be updated with the form value? foreach ($_POST['add'] as $key => $value) mysql_query("UPDATE $membtable SET m_".$key."='".sql_escape_string(stripslashes($value))."' WHERE m_id=$id"); Quote Link to comment https://forums.phpfreaks.com/topic/126636-update-query-question/#findComment-654864 Share on other sites More sharing options...
revraz Posted October 1, 2008 Share Posted October 1, 2008 Try it? Quote Link to comment https://forums.phpfreaks.com/topic/126636-update-query-question/#findComment-655005 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.