HDFilmMaker2112 Posted July 14, 2011 Share Posted July 14, 2011 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.'; } } Quote Link to comment Share on other sites More sharing options...
trq Posted July 14, 2011 Share Posted July 14, 2011 array_walk returns a bool. It operates on your array by reference so you would only need.... array_walk($credits, 'trim_value'); not.... $credits=array_walk($credits, 'trim_value'); Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted July 14, 2011 Author Share Posted July 14, 2011 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>'; } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.