如何成功注册,将表一列的内容复制到另一列? [英] How to do registration successful, copy the contents of one column of the table to the other?
本文介绍了如何成功注册,将表一列的内容复制到另一列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何成功注册,将表的一列的内容复制到另一列?例如,成功注册后,将自动复制users => id
到users => url
.我没意识到.请帮我创建一个函数!!!
How to do registration successful, copy the contents of one column of the table to the other? For example successful registration, automatic copy users => id
for users => url
. I can not realize it. Please help me to create a function!!!
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);
}
?>
推荐答案
在插入查询之后...获取最后一个插入ID并更新行
After Insert query... fetch the last insert id and update the row
$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 );
这篇关于如何成功注册,将表一列的内容复制到另一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文