简体   繁体   中英

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. I have used this code but got no result. No data can be seen in the exco table. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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