jac.kock Posted September 16, 2012 Share Posted September 16, 2012 hi all, i want to run in my cms a script that can set up or remove a user_block. what i have so var will set 1 tot the database but i cant seem to return it to 0, so i hope that someone will help me to solve it! code so var: // this function is called in a form with while(ect....) <checkbox id='[b]' value='$user_id'> for more than one user //set blokkeren function set_blok($blk) { foreach($blk as $var) { if($blk[$a]=='') { $set='0'; } else { $set='1'; } //this i tryed to see if it needs to be 0 or 1 $sql="update users set blokkeren='$set' where user_id='$var'"; $res=mysql_query($sql); } if(!$res) { return false; } else { return true; } } Link to comment https://forums.phpfreaks.com/topic/268438-need-help-to-solve-this/ Share on other sites More sharing options...
Jessica Posted September 16, 2012 Share Posted September 16, 2012 What is $a? Link to comment https://forums.phpfreaks.com/topic/268438-need-help-to-solve-this/#findComment-1378390 Share on other sites More sharing options...
jac.kock Posted September 16, 2012 Author Share Posted September 16, 2012 hi, $a was for a test i did i used it like: function set_blok($blk) { foreach($blk as $var;$a=$a++) { if($blk[$a]=='') { $set='0'; } else { $set='1'; } //this i tryed to see if it needs to be 0 or 1 $sql="update users set blokkeren='$set' where user_id='$var'"; $res=mysql_query($sql); } if(!$res) { return false; } else { return true; } } i tryed to get each $blk array i want when i uncheck the box that it set it to 0 en by checked to 1 can you help me? thnx Link to comment https://forums.phpfreaks.com/topic/268438-need-help-to-solve-this/#findComment-1378394 Share on other sites More sharing options...
Jessica Posted September 16, 2012 Share Posted September 16, 2012 In your code in your first post, there is no $a. So you will always be setting $set = 0. Link to comment https://forums.phpfreaks.com/topic/268438-need-help-to-solve-this/#findComment-1378425 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.