grabenair Posted August 7, 2012 Report Share Posted August 7, 2012 When I click the update user on the site I get all of these errors. I am so lost and flustered. When I put the print_R($update); die(); I get these errorrs with the query commited out. Warning: array_walk() [function.array-walk]: The argument should be an array in /home/sassy/public_html/cms/core/functions/users.php on line 5 Warning: Invalid argument supplied for foreach() in /home/sassy/public_html/cms/core/functions/users.php on line 6 When I uncommit the query and take out print_r($update); ie();I get this error: Parse error: syntax error, unexpected T_VARIABLE in /home/sassy/public_html/cms/core/functions/users.php on line 19 If Ben is checking this, if you did not delete the pm the info is the same if that helps you. I have not changed it yet. <?php function update_user($update_data){ global $session_user_id; $update = array(); line 5=> array_walk($update_data, 'array_sanitize'); foreach($update_data as $field=>$data){ $update[] = '`' . $field . '` = \'' . $data . '\''; } print_r($update); die(); //mysql_query("UPDATE `users` SET " . implode(', `, $update) . " WHERE `user_id` = . $session_user_id") or die(mysql_error()); } function activate($email, $email_code){ $email = mysql_real_escape_string($email); $email_code = mysql_real_escape_string($email_code); line 19=> if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1){ mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'"); return true; }else{ return false; } } function change_password($user_id, $password){ $user_id = (int)$user_id; $password = md5($password); mysql_query("UPDATE `users` SET `password` = '$password' WHERE `user_id` = $user_id"); } function register_user($register_data){ array_walk($register_data, 'array_sanitize'); $register_data['password'] = md5($register_data['password']); $fields = '`' . implode('`, `', array_keys($register_data)) . '`'; $data = '\'' . implode('\', \'', $register_data) . '\''; mysql_query("INSERT INTO `users` ($fields) VALUES ($data)"); email($register_data['email'], 'Activate your account', "Hello " . $register_data['first_name'] . ",\n\nYou need to activate your account to login, please use the link bellow:\n\nhttp://www.midwestwebdesignstudio.com/cms/activate.php?email=" . $register_data['email'] . "&email_code=" . $register_data['email_code'] . "\n\nThank You The web site goes here " ); } function user_count() { return mysql_result(mysql_query("SELECT COUNT(`user_id`)FROM `users` WHERE `active` = 1"), 0); } function user_data($user_id) { $data = array(); $user_id = (int)$user_id; $func_num_args = func_num_args(); $func_get_args= func_get_args(); if ($func_num_args > 1){ unset($func_get_args[0]); $fields = '`' . implode('`, `', $func_get_args) . '`'; $data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM `users` WHERE `user_id` = $user_id")); return $data; } } function logged_in() { return (isset($_SESSION['user_id'])) ? true : false; } function user_exists($username){ $username = sanitize($username); return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"), 0) == 1) ? true : false; } function email_exists($email){ $email = sanitize($email); return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email'"), 0) == 1) ? true : false; } function user_active($username){ $username = sanitize($username); return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `active` = 1"), 0) == 1) ? true : false; } function user_id_from_username($username){ $username = sanitize ($username); return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username' "), 0, 'user_id'); } function login($username, $password) { $user_id = user_id_from_username($username); $username =sanitize($username); $password = md5($password); return(mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"),0) ==1) ? $user_id : false; } ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted August 7, 2012 Report Share Posted August 7, 2012 I'd suggest working on one error at a time. $update is an array, because you defined it as an array in line 4. What you need to be checking is $update_data. I'm guessing it isn't an array, which is giving you these errors. I'd suggest confirming that by adding print_r($update_data); exit(); right above the array_walk() function. Quote Link to comment Share on other sites More sharing options...
grabenair Posted August 7, 2012 Author Report Share Posted August 7, 2012 I'd suggest working on one error at a time. $update is an array, because you defined it as an array in line 4. What you need to be checking is $update_data. I'm guessing it isn't an array, which is giving you these errors. I'd suggest confirming that by adding print_r($update_data); exit(); right above the array_walk() function. this is my $update_data $update_data = array( 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'email' => $_POST['email'], ); Here is what I am doing for now to fix it. I went and committed everything out dealing with the errors and am moving on. This is a big project for someone who has only done tutorials of php on just what are functions, if statements etcetera. When I learn a little more I will come back and visit this some more. I thought I was ready for this because I do a lot of wordpress sites and can figure out what php I need to change or remove to make the site do what I want. I was wrong. Being a old school Marine it is really hard for me to admit defeat but here goes. 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.
Note: Your post will require moderator approval before it will be visible.