Hello everyone! Please help me on how to append the content of 1 table to another. I have coded but there is an error, please check if you have comments. If you have sample code the better.

$result2 = mysql_query(INSERT INTO billingstatementhistory values (SELECT * FROM billingstatement);

error is: Parse error: parse error, unexpected T_STRING in C:\websites\billingstatementtest.php on line 125

I am using Php5 and MySQL.

Your help is very much appreciated . Thank you.

The error you get (...unexpected T_STRING ...) means you try to use an unquoted string; the mysql_query (the part between parenthesis) must be quoted.
Anyway, I'm not sure the mysql statement works that way!!!

Here's my new code:

$result2 = mysql_query("insert into billingstatementhistory(billingStatementNo, transactionDate, transactionType, subjectCode, clientID, attorneyID, rateHour, consumedHour, currency, legalFees, checkInvoice) SELECT billingStatementNo, transactionDate, transactionType, subjectCode, clientID, attorneyID, rateHour, consumedHour, currency, legalFees, checkInvoice FROM billingstatement");

No error occured but it does not append the content of table1 to table2. plsss help.....

Try this

$query_1 = "SELECT billingStatementNo, transactionDate, transactionType, subjectCode, clientID, attorneyID, rateHour, consumedHour, currency, legalFees, checkInvoice FROM billingstatement";
 
$result_1 = mysql_query ($query_1) or die (mysql_error());
if (mysql_num_rows($result_1) <1) {
die ('No data to transfer');
}
else {
while ($src_row = mysql_fetch_row($result_1)) {
$row = implode ("','",$src_row);
$query_2 = "insert into billingstatementhistory(billingStatementNo, transactionDate, transactionType, subjectCode, clientID, attorneyID, rateHour, consumedHour, currency, legalFees, checkInvoice) values ('$row')";
$result_2 = mysql_query($query_2) or die (mysql_error());
}
}

Thanks for helping me John. I did find a solution to my problem. But for sure, i will try to implement your code as well. Maybe that would be better than the code I made. I very much appreciate your contribution and help. Thanks....

Wishing you a box office hit for your upcoming movie Pirates. hehehe

I'm glad you found a solution to your problem; see you arround.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.