acctman Posted March 17, 2009 Share Posted March 17, 2009 what's the easiest way to have checkboxes? I need to store a '0' for no or '1' for yes in the mysql db Link to comment https://forums.phpfreaks.com/topic/149881-easiest-way-to-handle-checkboxes/ Share on other sites More sharing options...
supanoob Posted March 17, 2009 Share Posted March 17, 2009 what's the easiest way to have checkboxes? I need to store a '0' for no or '1' for yes in the mysql db there is only one way isnt there? if on then yes if off then no? Link to comment https://forums.phpfreaks.com/topic/149881-easiest-way-to-handle-checkboxes/#findComment-787093 Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 i use an INT with 1 or 0 edit: you should probably use TINYINT actually Link to comment https://forums.phpfreaks.com/topic/149881-easiest-way-to-handle-checkboxes/#findComment-787094 Share on other sites More sharing options...
acctman Posted March 17, 2009 Author Share Posted March 17, 2009 i use an INT with 1 or 0 edit: you should probably use TINYINT actually i have the fields set for ENUM('0','1'), am i doing something wrong because its not saving anything. if ($en['act'] == 'prefs') { sql_query("UPDATE $membtable SET m_comme=".(int)($en['m_com_me'] == 'ON'). ", m_ziphide=".(int)($en['m_ziphide'] == 'ON'). ", m_msg_alerts=".(int)($en['alert_me'] == 'ON'). ", m_blockmsgs=".(int)($en['m_blockmsgs'] == 'ON'). ", m_fview=".(int)($en['m_fview'] == 'ON'). ", m_news=".(int)($en['m_news'] == 'ON'). " WHERE m_id=$en[m_id]"); } Link to comment https://forums.phpfreaks.com/topic/149881-easiest-way-to-handle-checkboxes/#findComment-787106 Share on other sites More sharing options...
laffin Posted March 17, 2009 Share Posted March 17, 2009 I dun have php in front of me. But when it comes to true and false bools ya shud be careful as false is always 0 however true can equate to a number of different things. !false flips all the bits in the word, and becomes -1. Which ya will see a lot of mention about. so it will fail the enum(0,1) portion as -1 isnt enumerated. And remember true/false value is dictated by the app. PHP true/false bools may be different than mysql so yer best bet, is to use a trenary operator. forcing to 1 (int)($en['m_ziphide'] == 'ON'?1:0) Link to comment https://forums.phpfreaks.com/topic/149881-easiest-way-to-handle-checkboxes/#findComment-787138 Share on other sites More sharing options...
acctman Posted March 18, 2009 Author Share Posted March 18, 2009 hmm i tried I dun have php in front of me. But when it comes to true and false bools ya shud be careful as false is always 0 however true can equate to a number of different things. !false flips all the bits in the word, and becomes -1. Which ya will see a lot of mention about. so it will fail the enum(0,1) portion as -1 isnt enumerated. And remember true/false value is dictated by the app. PHP true/false bools may be different than mysql so yer best bet, is to use a trenary operator. forcing to 1 (int)($en['m_ziphide'] == 'ON'?1:0) i tried that still not saving a value Link to comment https://forums.phpfreaks.com/topic/149881-easiest-way-to-handle-checkboxes/#findComment-787275 Share on other sites More sharing options...
acctman Posted March 18, 2009 Author Share Posted March 18, 2009 ok i changed all the db fields to tinyint but i still can't get the values to save. Link to comment https://forums.phpfreaks.com/topic/149881-easiest-way-to-handle-checkboxes/#findComment-787734 Share on other sites More sharing options...
acctman Posted March 18, 2009 Author Share Posted March 18, 2009 can anyone help? Link to comment https://forums.phpfreaks.com/topic/149881-easiest-way-to-handle-checkboxes/#findComment-787924 Share on other sites More sharing options...
laffin Posted March 18, 2009 Share Posted March 18, 2009 I think I might have seen the problem WHERE m_id=$en[m_id] note the m_id in the braces, there is a problem there, is this a mysql variable or a php one? Link to comment https://forums.phpfreaks.com/topic/149881-easiest-way-to-handle-checkboxes/#findComment-788129 Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 a php variable. put the query into a string first so you can echo it: $sql = "UPDATE $membtable SET m_comme=".(int)($en['m_com_me'] == 'ON'). ", m_ziphide=".(int)($en['m_ziphide'] == 'ON'). ", m_msg_alerts=".(int)($en['alert_me'] == 'ON'). ", m_blockmsgs=".(int)($en['m_blockmsgs'] == 'ON'). ", m_fview=".(int)($en['m_fview'] == 'ON'). ", m_news=".(int)($en['m_news'] == 'ON'). " WHERE m_id=$en[m_id]"; echo $sql; sql_query($sql); Link to comment https://forums.phpfreaks.com/topic/149881-easiest-way-to-handle-checkboxes/#findComment-788166 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.