Jump to content

Easiest way to handle checkboxes?


acctman

Recommended Posts

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]");    
}

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)

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

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);  

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.