我需要将字段内的数据复制到另一个字段。我需要复制" 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");
}
?>
答案 0 :(得分:0)
你能这样做吗?
('$_POST[connect_date]',
'$_POST[reg]',
'$_POST[reg]',
'$_POST[first_name]',
'$_POST[last_name]')";
答案 1 :(得分: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])."';
或者我理解你的问题错了? :/然后提供更多信息。
答案 2 :(得分: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");
}
?>