0

我需要将一个字段内的数据复制到另一个字段。插入记录时,我需要将“reg”复制到“reg_copy”。有没有办法在我的脚本中做到这一点?

<?
$order = "INSERT INTO reg_add ( 
connect_date, 
reg, 
reg_copy,
first_name, 
last_name)

VALUES

('$_POST[connect_date]', 
'$_POST[reg]',
'$_POST[reg_copy]',
'$_POST[first_name]', 
'$_POST[last_name]')";

$result = mysql_query($order);

if ($result) {

$reg =      $_REQUEST['reg'] ;
$first_name =   $_REQUEST['first_name'];

header("location: reg_add_success.php?reg=" . urlencode($reg) . "&first_name=" . urlencode($first_name));
}
else {
header("location: reg_add_fail.php");
}
?>
4

3 回答 3

0

你能做这个吗?

('$_POST[connect_date]', 
'$_POST[reg]',
'$_POST[reg]',
'$_POST[first_name]', 
'$_POST[last_name]')";
于 2012-04-24T14:25:02.417 回答
0

是的,只需使用:

$order = "INSERT INTO reg_add set 
`connect_date` = '".mysql_real_escape_string($_POST[connect_date])."',
`reg` = '".mysql_real_escape_string($_POST[reg])."',
`reg_copy` = `reg`,
`first_name` = '".mysql_real_escape_string($_POST[first_name])."',
`last_name` = '".mysql_real_escape_string($_POST[last_name])."';

或者也许我理解你的问题是错误的?:/然后提供更多信息。

于 2012-04-24T14:33:21.803 回答
0

也许你应该更清楚你的问题,我不是 100% 确定你的意思,但从阅读你的问题看起来你想要这样做:

<?
$order = "INSERT INTO reg_add ( 
connect_date, 
reg, 
reg_copy,
first_name, 
last_name
) VALUES ("
'".mysql_real_escape_string($_POST[connect_date])"', 
'".mysql_real_escape_string($_POST[reg])."',
'".mysql_real_escape_string($_POST[reg])."',
'".mysql_real_escape_string($_POST[first_name])."', 
'".mysql_real_escape_string($_POST[last_name])."'
")";

/* Always use mysql_real_escape_string on your POST and GET */

$result = mysql_query($order);

if ($result) {

$reg =      $_REQUEST['reg'] ;
$first_name =   $_REQUEST['first_name'];

header("location: reg_add_success.php?reg=" . urlencode($reg) . "&first_name=" .     urlencode($first_name));
}
else {
header("location: reg_add_fail.php");
}
?>
于 2012-04-24T14:51:07.417 回答