Jump to content

array_walk causing foreach error


HDFilmMaker2112

Recommended Posts

The below is resulting in an error of:

 

Warning: Invalid argument supplied for foreach() in /home/zyquo/public_html/makethemoviehappen.com/admin_users.php on line 145

 

Seems like it's an issue with array_walk. Worked fine until I added that.

 


function trim_value(&$value) 
{ 
    $value = trim($value); 
}


elseif($_GET['do']="process"){
$source=sanitize($_GET['source']);
$name=sanitize($_POST['name']);
$email=sanitize($_POST['email']);
$amount=amount_verify(sanitize($_POST['amount']));
$username=sanitize($_POST['username']);
$level=sanitize($_POST['level']);
$password=kam3($_POST['password']);
$admin=sanitize($_POST['user_level']);
$credits=sanitize($_POST['credit']);
$credits=explode(",",$credits);
$credits=array_walk($credits, 'trim_value');

if($amount=="00" || $amount==".00"){
$amount="";
}

if($_GET['source']=="new"){
$add_user_query="INSERT INTO $tbl_name (username, name, level, amount, password, admin, email) VALUES ('$username', '$name', '$level', '$amount', '$password', '$admin', '$email')";
mysql_query($add_user_query);
$insert_id=mysql_insert_id();
if(!empty($credits)){
$CreditArray = array();
foreach($credits as $credit){
$CreditArray[] = "('$credit',$insert_id)";
}
if (count($CreditArray) > 0 ){
$credit_array_query="INSERT IGNORE INTO $tbl_name2 (credit,donor_id) VALUES " . implode(',',$CreditArray);
mysql_query($credit_array_query);
}
if(mysql_affected_rows()==1){
$content.='User Added.';
}
}

Link to comment
https://forums.phpfreaks.com/topic/241968-array_walk-causing-foreach-error/
Share on other sites

Excellent thanks.

 

 

Now I have another issue.

 

When I enter

 

Test2 as my username

 

and Test, Test2 as the credits.

 

I get a page that only says User Added.

 

Should Say:

 

User Added.

User Credits Added.

 

 

After looking in the Database it looks like the data is indeed being added.

 

Updated code:

 

$source=sanitize($_GET['source']);
$name=sanitize($_POST['name']);
$email=sanitize($_POST['email']);
$amount=amount_verify(sanitize($_POST['amount']));
$username=sanitize($_POST['username']);
$level=sanitize($_POST['level']);
$password=kam3($_POST['password']);
$admin=sanitize($_POST['user_level']);
$credits=sanitize($_POST['credit']);
$credits=explode(",",$credits);
array_walk($credits, 'trim_value');

if($amount=="00" || $amount==".00"){
$amount="";
}

if($_GET['source']=="new"){
$add_user_query="INSERT INTO $tbl_name (username, name, level, amount, password, admin, email) VALUES ('$username', '$name', '$level', '$amount', '$password', '$admin', '$email')";
mysql_query($add_user_query);
$insert_id=mysql_insert_id();
if(!empty($credits)){
$CreditArray = array();
foreach($credits as $credit){
$CreditArray[] = "('$credit',$insert_id)";
}
if(mysql_affected_rows()==1){
$content.='<div class="center">User Added.</div>';
}
if (count($CreditArray) > 0 ){
$credit_array_query="INSERT IGNORE INTO $tbl_name2 (credit,donor_id) VALUES " . implode(',',$CreditArray);
mysql_query($credit_array_query);
}
if(mysql_affected_rows()==1){
$content.='<div class="center">User Credits Added.</div>';
}
}

}

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.