09/10/2018, 23:41

[Help] Sửa dùm đoạn code bị lỗi

Code:
<form name="form2" method="post" action="">
  <input name="per[1]" type="checkbox" id="per[1]" value="1">
  1
  <input name="per[2]" type="checkbox" id="per[2]" value="1"> 
  2 
  <input type="checkbox" name="checkbox" value="checkbox">
  ne***7913;
</form>
<form name="form1" method="post" action="">
</form>
<?
function array2bin($arrayList)
{
	$box = $arrayList;
	$lang=0;
	$i=1;
	for ($j=0;$j<24;$j++,$i*=2)
	{
//		echo 'ID: '.($j+1).' -> '.$box[($j+1)].'<br>';
		$lang += $i*(!$box[($j+1)]?0:1);
	}
	return $lang;
}
		
function bin2array($bin)
{
	$tabl = $bin;
	$tlist=array();
	$i=1;
	for ($j=0;$j<24;$j++,$i*=2)
		{
			$tlist[$j+1]=$tabl & $i;
			if ($tlist[$j+1]!=0) 
				$la[$j+1] = 'checked';
		}
	return $la;
}

	//save permission
	// check input box name: per[1] per[2] per[3] (check box value = 1)
	$permission = array2bin($_POST['per']);
	
	
	//get permission from database
	$permission = bin2array($data['usergroupID']);
	

	if ($permission[1])
	{
	///
	}



?>
Em có đoạn code như trên nhưng khi chạy thử thì nó bị báo lỗi như sau:

Code:
Notice: Undefined offset: 2 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 4 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 5 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 6 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 7 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 8 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 9 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 10 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 11 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 12 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 13 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 14 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 15 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 16 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 17 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 18 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 19 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 20 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 21 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 22 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 23 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12

Notice: Undefined offset: 24 in C:Documents and SettingsWelcomeDesktopTAKEadmincpadd_mod.php on line 12
Các bác giúp dùm em khắc phục đoạn code này với
conmalele viết 01:56 ngày 10/10/2018
Sửa lại thành
PHP Code:
function array2bin($arrayList)
{
if(empty(
$arrayList)) return false;
/**/
if(empty($arrayList)) $arrayList 1;
    
$box $arrayList;
    
$lang=0;
    
$i=1;
    for (
$j=0;$j<24;$j++,$i*=2)
    {
//        echo 'ID: '.($j+1).' -> '.$box***91;($j+1)***93;.'<br>';
        
$lang += $i*(!$box***91;($j+1)***93;?0:1);
    }
    return 
$lang;

PHP Code:
if(isset($_POST***91;'per'***93;))
    
$permission array2bin($_POST***91;'per'***93;); 
Ruan Ios viết 01:51 ngày 10/10/2018
huhu bác nói rõ dùm em với em sửa theo như bác nói rồi nhưng vẫn bị báo lỗi như cũ hic.
TheHeTre viết 01:45 ngày 10/10/2018
Sửa lại dòng 12:

Code:
function array2bin($arrayList = array())
Ruan Ios viết 01:49 ngày 10/10/2018
huhu bác nào giúp em với, sửa theo cách của mấy`bạn rồi nhưng vẫn bị lỗi
Bài liên quan
0