简体   繁体   English

从 1 个表中获取行并将其插入到另一个表中

[英]Fetching rows from 1 table and inserting it into another

I have to fetch all the rows from table workplan_progress and insert it to another table exco.我必须从表 workplan_progress 中获取所有行并将其插入另一个表 exco。 I have used this code but got no result.我已经使用了这段代码,但没有结果。 No data can be seen in the exco table. exco 表中看不到任何数据。 I tried a lot of other methods too but kept getting no answer at all.我也尝试了很多其他方法,但始终没有得到任何答案。

include("includes/connect.php");
$id=$_GET['id'];
$sql="SELECT * FROM workplan_progress where id='$id'";
$query=mysql_query($sql);
$row=mysql_fetch_array($query, MYSQL_ASSOC);

$value1 = $row['division_name'];
$value2 = $row['division_chief'];
$value3 = $row['period'];
$value4 = $row['month'];
$value5 = $row['activity_name'];
$value6 = $row['unit'];
$value7 = $row['weightage'];
$value8 = $row['per_100'];
$value9 = $row['per_75'];
$value10 = $row['per_50'];
$value11 = $row['per_<50'];
$value12 = $row['measurement'];
$value13 = $row['score'];
$value14 = $row['progress'];
$value15 = $row['indicator_measure'];

$sql1 = "INSERT INTO 'exco' SET                 division_name='$value1',
                                                division_chief='$value2',
                                                period='$value3',
                                                month='$value4',
                                                activity_name='$value5',
                                                unit='$value6',
                                                weightage='$value7',
                                                per_100='$value8',
                                                per_75='$value9',
                                                per_50='$value10',
                                                perless50='$value11'
                                                measurement='$value12'
                                                score='$value13'
                                                progress='$value14'
                                                indicator_measure='$value15'
                                                ";

$query1 = mysql_query($sql1);
if(isset($query1)){
        $_SESSION['msg']='This work progress has been forwarded to exco for approval.';
    }
    echo "<script>window.location='admin_workprogress.php?msg=success'</script>";

?> ?>

You have single quotes around the name of the table here:您在此处的表名称周围有单引号:

$sql1 = "INSERT INTO 'exco' SET

What you need is either this without single quotes:你需要的是没有单引号的这个:

$sql1 = "INSERT INTO exco SET

or better, this with backticks:或者更好,这带有反引号:

$sql1 = "INSERT INTO `exco` SET

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM