Как сделать успешную регистрацию, скопировать содержимое одного столбца таблицы в другое? Например, успешная регистрация, автоматическая копия users => id
для users => url
. Я не понимаю. Пожалуйста, помогите мне создать функцию !!!
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)"); }
<?php include 'core/init.php'; if (empty($_POST) === false) { $required_fields = array('username', 'password', 'password_again', 'first_name', 'email'); foreach($_POST as $key=>$value) { if (empty($value) && in_array($key, $required_fields) === true) { $errors[] = '<div id="result_x"><i class="fa fa-times"></i></div><div id="error">Fill in all fields to continue registration.</div>'; break 1; } } if (empty($errors) === true) { if (user_exists($_POST['username']) === true) { $errors[] = '<div id="result_x"><i class="fa fa-times"></i></div><div id="error">Unfortunately, the user name <b>' . $_POST['username'] . '</b> It is already in use.</div>'; } if (preg_match("/\\s/", $_POST['username']) == true) { $errors[] = '<div id="result_x"><i class="fa fa-times"></i></div><div id="error">Your user name should not contain spaces.</div>'; } if (strlen($_POST['password']) < 6) { $errors[] = '<div id="result_x"><i class="fa fa-times"></i></div><div id="error">Your password must be at least 6 characters.</div>'; } if ($_POST['password'] !== $_POST['password_again']) { $errors[] = '<div id="result_x"><i class="fa fa-times"></i></div><div id="error">Your passwords do not match.</div>'; } if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) { $errors[] = '<div id="result_x"><i class="fa fa-times"></i></div><div id="error">A valid email address is required.</div>'; } if (email_exists($_POST['email']) === true) { $errors[] = '<div id="result_x"><i class="fa fa-times"></i></div><div id="error">Unfortunately, e-mail address <b>' . $_POST['email'] . '</b> It is already in use.</div>'; } } } ?> <?php if (empty($_POST) === false && empty($errors) === true) { $register_data = array( 'username' => $_POST['username'], 'password' => $_POST['password'], 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'email' => $_POST['email'] ); register_user($register_data); echo '<div id="result_x"><i class="fa fa-times"></i></div><div id="error">You have successfully registered!</div>'; } else if (empty($errors) === false) { echo output_errors($errors); } ?>
После запроса вставки … введите последний идентификатор вставки и обновите строку
$insert = "INSERT INTO users($fields) VALUES ($data) "; mysqli_query($con,$insert); $last_id = mysqli_insert_id($con); $update = "UPDATE users SET url = '".$last_id."' WHERE id = ".$last_id." "; mysqli_query($con,$update );