将数据从一张表复制到另一张表? [英] copy data from one table into another?

查看:77
本文介绍了将数据从一张表复制到另一张表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户注册我的网站时,他们会填写注册表并将他们的详细信息放入名为 ptb_registrations 的表格中.

when a user signs up to my site they complete a registration form and have their details put into a table called ptb_registrations.

在此之后,他们收到一封带有验证码的电子邮件,他们单击电子邮件链接并转到验证链接,输入正确的代码后,我希望运行查询.

after this they receive an email with a verification code, they click the email link and go to the verification link, upon entering the correct code i want a query to run.

此查询需要充当插入查询,将数据从一个表 (ptb_registrations) 复制到另一个表 (ptb_users).

this query needs to act as an insert query that will copy the data from one table (ptb_registrations) into another (ptb_users).

有人可以帮我解决这个问题,因为它不起作用,我不确定我是否朝着正确的方向前进.谢谢

can someone help me with this as it's not working and im not sure if im heading in the right direction. thanks

// Make a safe query
$query = sprintf("INSERT INTO ptb_users (first_name, last_name, email,    
    password, dob)
SELECT firstname, lastname, email, password    
    dob
WHERE not exists (select 1 from ptb_registrations where ptb_registrations.registration_code='$verificationcode';",
                    mysql_real_escape_string($newpassword));

mysql_query($query)or die('Could not update members: ' . mysql_error());

推荐答案

据我所知,你的查询中有很多语法错误:

As far as I can see, you have a lot of syntax mistakes in your query:

select 语句中 password 和 dob 之间没有逗号,未指定来自 select 语句的表.此外, where 条件看起来很奇怪(并且 not exists 语句没有右括号).至于我,你应该有这样的查询:

no comma between password and dob in select statement, From table for select statement is not specified. Also, where condition looks strange (and there is no closing bracket for not exists statement). As for me, you should have a query like:

$query = "INSERT INTO ptb_users (first_name, last_name, email, password, dob)
SELECT firstname, lastname, email,'". mysql_real_escape_string($newpassword)."', dob FROM ptb_registrations
WHERE ptb_registrations.registration_code=''". mysql_real_escape_string($$verificationcode).";"

此查询将从 ptb_registrations 中获取一行,其中注册码等于从请求中收到的注册码,并将其插入到 ptb_users 中(并将新密码作为用户密码)

This query will take a row from ptb_registrations where registration code is equal to one received from request and insert it into ptb_users (and put a new password as a user password)

这篇关于将数据从一张表复制到另一张表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆